如何防止使用 tkinter 调整窗口大小? [英] How can I prevent a window from being resized with tkinter?

查看:52
本文介绍了如何防止使用 tkinter 调整窗口大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以创建一个窗口,根据复选框显示消息.

I have a program which creates a window where a message is displayed according to a check box.

如何在显示消息和不显示消息时使窗口大小恒定?

How can I make the window size constant when the message is displayed and the message is not displayed?

from Tkinter import *

class App:
    def __init__(self,master):
        self.var = IntVar()
        frame = Frame(master)
        frame.grid()
        f2 = Frame(master,width=200,height=100)
        f2.grid(row=0,column=1)
        button = Checkbutton(frame,text='show',variable=self.var,command=self.fx)
        button.grid(row=0,column=0)
        msg2="""I feel bound to give them full satisfaction on this point"""
        self.v= Message(f2,text=msg2)
    def fx(self):
        if self.var.get():
            self.v.grid(column=1,row=0,sticky=N)
        else:
            self.v.grid_remove()

top = Tk()
app = App(top)            
top.mainloop()

推荐答案

这段代码创建一个窗口,条件是用户不能改变 Tk() 窗口的尺寸,同时也禁用了最大化按钮.

This code makes a window with the conditions that the user cannot change the dimensions of the Tk() window, and also disables the maximise button.

import tkinter as tk

root = tk.Tk()
root.resizable(width=False, height=False)
root.mainloop()

在程序中,您可以使用@Carpetsmoker 的回答或通过执行以下操作来更改窗口尺寸:

Within the program you can change the window dimensions with @Carpetsmoker's answer, or by doing this:

root.geometry('{}x{}'.format(<widthpixels>, <heightpixels>))

在您的代码中实现它应该相当容易.:)

It should be fairly easy for you to implement that into your code. :)

这篇关于如何防止使用 tkinter 调整窗口大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆