我尝试使用Python3中的类创建一个简单的菜单。我曾经尝试过用“其他菜单”按钮创建一个初始菜单,然后单击它就会转到另一个带有“这是其他菜单”按钮的菜单。你知道吗
不过,它目前只是在启动时显示两个菜单。你知道吗
最终我想有一个12个按钮的初始菜单,然后将重定向到其他菜单。我可以通过创建一个新窗口来实现这一点,但我更希望它保持在同一个窗口中。你知道吗
我在下面做错了什么?你知道吗
#import the tkinter module
from tkinter import *
#create a new class
class Try(Frame):
def __init__(self, master):
super(Try, self).__init__(master)
self.grid(row = 2, sticky = W+E+N+S)
#,padx=300
self.create_widgets()
def create_widgets(self):
#create buttons
self.bttn1 = Button(self, text = 'Other Menu')
self.bttn1['command'] = self.create_widgets2()
self.bttn1.grid(sticky = W+E+N+S)
def create_widgets2(self):
#create buttons
self.bttn2 = Button(self, text = 'This is the other menu')
self.bttn2.grid(sticky = W+E+N+S)
#main
root = Tk()
root.title('Editor')
root.geometry()
root.configure(background='black')
app = Try(root)
root.mainloop()
分配按钮的
command
选项时,您正在调用create_widgets2
方法中的create_widgets
方法:您需要删除括号,以便
command
选项只分配给函数对象:相关问题 更多 >
编程相关推荐