Tkinter GUI问题

Tkinter GUI问题

问题描述:

即时通讯工作在项目,但它不太好。
此代码:Tkinter GUI问题

from tkinter import * 

def NewFile(): 
    new = Label(root, text="about \n") 
def OpenFile(): 
    openf = Label(root, text="about \n") 
def About(): 
    about = Label(root, text="about \n") 

root = Tk() 
menu = Menu(root) 
root.config(menu=menu) 
filemenu = Menu(menu) 
menu.add_cascade(label="File", menu=filemenu) 
filemenu.add_command(label="New", command=NewFile) 
filemenu.add_command(label="Open...", command=OpenFile) 
filemenu.add_separator() 
filemenu.add_command(label="Exit", command=root.quit) 

helpmenu = Menu(menu) 
menu.add_cascade(label="Help", menu=helpmenu) 
helpmenu.add_command(label="About...", command=About) 
body = Label(root, text="") 
mainloop() 

不工作我怎么需要它。
当您点击file > new,file > openhelp > about时,它被置于写入证明消息。

它什么都不做

我怎么可以把它做什么想要什么?

@Lafexlos是正确的。 您可以在GUI设计中使用所有python类型(列表,字典,变量和更多...),最重要的点how to manage all GUI elements,所以都需要一个可访问的状态。

不要destroy任何GUI元素,更改和重用它。

不包括任何外部命令mainloop(如:文件,网络等)

所有GUI应用程序所需的3关键部分:INIT >> BUILD >> RUN否则,你得到了很多痛苦。

使用GUI元素text作为variable,当然如果所有元素都是可访问的!

我希望有帮助,并接受@Lafexlos答案不是我的! 此代码在Python2.7上工作

你不在你的小部件上使用几何管理器(包/网格/地点),所以tkinter不会显示给你。另外,不是每次点击都创建新的标签,您可以在全局范围内创建全部三个,也可以在点击时创建一个标签并根据您的需要更改其值。