我有一个标签设置为一定的大小但是当我运行我的程序时,主窗口不够大,无法看到整个标签。 如何增加主窗口的大小?我尝试了不同的选择,但我没有运气。
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()
答案 0 :(得分:2)
如果您使用pack
或grid
代替place
,则窗口会自动增大或缩小以适合标签的内容。如果有的话,place
最好用得非常谨慎。
如果您想使用place
,可以使用根窗口的geometry
方法为窗口指定显式大小。
例如,要使根窗口为600x100,您应该添加以下行:
root.geometry("600x100")