python - 在 Tkinter、Python 3 中设置窗口尺寸

标签 python python-3.x tkinter

我以前做过很多 Tkinter Python 应用程序,但我从来没有遇到过这个问题:

如何使用 Python 3 在 Tkinter 中设置初始(根)窗口的尺寸?

我遇到了 this question其中详细说明了 Python 2.7 的答案,但 Tkinter 已针对 Python 3 进行了更新,因此该解决方案不起作用。

这是令人讨厌的代码:

class Application(tk.Frame):    
    def __init__(self, master=None):
        tk.Frame.__init__(self,master)
        self.grid()
        self.createWidgets()
        master.minsize(width=500,height=500)

app = Application()
app.master.title("MFPA")
app.mainloop()

master.minsize() 行来自引用的问题,但由于我的 master 对象是 None,该方法不会存在。

那里的第二个解决方案也不起作用,因为它依赖于调用 tk.Tk() 方法开始,而我正在使用更新的 Tkinter 和这种新的创建方法 window 。

最佳答案

tk.Frame.__init__ 调用应该会自动为您找到 master 并将其分配给对象的属性。尝试:

    self.master.minsize(width=500,height=500)

关于python - 在 Tkinter、Python 3 中设置窗口尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25690423/

相关文章:

python - param ['pagetoken' ] 是示例 Google 报告代码中的语法错误吗?

python - ('HY000' , 'The SQL contains 21 parameter markers, but 1 parameters were supplied' )

python-3.x - 检查消息回复是否为回复类型消息discord.py

python - 可以使用 Python 3 的数字格式将数字四舍五入到百、千等

python - 允许用户在 tkinter askopenfilename() 中键入路径

Python-打印字典中的多个内容时出现问题

python - 有没有一种在 Python 中使用二进制数的简单方法?

python - Tkinter,一次处理多个帧,每个帧中都有按钮。但是按钮忽略了给定的框架,只使用网格

python - 生成数百万个json数据

python - 让两个 Frames 各占可用宽度的 50%?