如何在Python中更改Tkinter主窗口的大小?

如何在Python中更改Tkinter主窗口的大小?,python,tkinter,Python,Tkinter,我有一个特定大小的标签,但当我运行程序时,主窗口不够大,无法看到整个标签。 如何增加主窗口的大小?我尝试过不同的选择,但我没有任何运气 import win32com.client import os # import threading # use the Timer import tkinter from tkinter import Tk, Label, Button class myGUI: def timer(self): import pythonco

我有一个特定大小的标签,但当我运行程序时,主窗口不够大,无法看到整个标签。 如何增加主窗口的大小?我尝试过不同的选择,但我没有任何运气

import win32com.client
import os
# import threading # use the Timer
import tkinter

from tkinter import Tk, Label, Button

class myGUI:

    def timer(self):

        import pythoncom       
        pythoncom.CoInitialize()  

        outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

        inbox = outlook.GetDefaultFolder(6) 



        messages = inbox.Items
        message = messages.GetLast()
        body_content = message.Subject # can be Body, To, REcipients, Sender, etc


        self.answer_label['text'] = (body_content) # orginally used body_content.encode("utf-8") to fixed character encoding issue


        self.master.after(20, self.timer) # after needs to be called from an existing widget such as master
                                         # In this case, the after method is used to refresh the e-mails instead of threading

    def __init__(self, master):
        self.master = master
        master.title("CheckStat")


        self.answer_label = Label(master, text='', fg="light green", bg="dark green", font="Helvetica 16 bold italic")
        self.answer_label.place(height=100, width=600)

        self.timer()


root = Tk()
my_gui = myGUI(root)
root.mainloop()

如果使用
pack
grid
而不是
place
,窗口将自动增大或缩小以适应标签内容<代码>位置最好尽量少用,如果有的话

如果要使用
place
,可以使用根窗口的
geometry
方法为窗口指定显式大小

例如,要使根窗口为600x100,应添加以下行:

root.geometry("600x100")

如果使用
pack
grid
而不是
place
,窗口将自动增大或缩小以适应标签内容<代码>位置最好尽量少用,如果有的话

如果要使用
place
,可以使用根窗口的
geometry
方法为窗口指定显式大小

例如,要使根窗口为600x100,应添加以下行:

root.geometry("600x100")

您必须使用
.place()
管理器吗?(您可能不需要)
.place()
忽略边界和位置相对而言,您可能希望使用其他窗口管理器(
.grid()
.pack()
),尽管前者将使您更容易学习,并省去一些麻烦-但请注意,这两个窗口管理器不能在同一容器中使用(相反,Tk将在我们太阳的余生中尝试解决它们。)不,我不必使用.place。我最初选择它是因为我认为它会给我更多的控制权。它可能会给我更多的控制权,但你不想要更多的控制权。你希望事情“正常运转”如果
.grid()
不能给你想要的东西,你可以移动到
.place()
去做特定的事情。但是
.grid()
可能在60%的情况下能给你想要的东西,
.pack()
将处理其余的99%。
.place()
在需要相对于整个窗口或其他元素进行定位时非常有用,但不是以
.grid()
句柄的方式,也对重叠的元素非常有用。您必须使用
.place()
管理器吗?(您可能不需要)
.place()
忽略边界和位置相对而言,您可能希望使用其他窗口管理器(
.grid()
.pack()
),尽管前者可以让您学到更多知识并省去一些麻烦-但请注意,这两种管理器不能在同一容器中使用(相反,Tk将在我们太阳的余生中尝试解决它们。)不,我不必使用.place。我最初选择它是因为我认为它会给我更多的控制权。它可能会给我更多的控制权,但你不想要更多的控制权。你希望事情“正常运转”如果
.grid()
不能给你想要的东西,你可以移动到
.place()
去做特定的事情。但是
.grid()
可能在60%的情况下能给你想要的东西,
.pack()
将处理99%的其余部分。
.place()
在需要相对于整个窗口或其他元素进行定位时非常有用,但不是以
.grid()
句柄的方式,而且对于重叠的元素也很有用。我想知道根.geometry()。我试过了,但似乎什么都没做。@Prox:它肯定有作用。它会将根窗口的大小强制到指定的大小。我想知道root.geometry()。我试过了,但似乎什么都没做。@Prox:它肯定有作用。它会将根窗口的大小强制到指定的大小。