【发布时间】:2014-11-15 17:33:29
【问题描述】:
我尝试使用 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()
【问题讨论】:
标签: python class python-3.x tkinter