【发布时间】:2017-05-15 21:00:02
【问题描述】:
我对 Python 还是很陌生,昨天开始学习 Tkinter。我正在创建一个银行系统,我有一个由按钮组成的菜单。我遇到的问题是单击按钮时我不知道如何打开其他窗口。我试过top=Toplevel(),但它只打开了两个相互重叠的窗口。我需要的是仅在使用按钮(事件)激活附加窗口时才打开它。有人可以帮我吗,因为我有大约六个按钮,我真的被卡住了?
到目前为止我的代码是:
root.minsize(width=400, height=400)
root.maxsize(width=400, height=400)
root.configure(background='#666666')
label = Frame(root).pack()
Lb = Label(label, text='Welcome to Main Menu',bg='#e6e6e6', width=400).pack()
menu = Frame(root,).pack()
btn_1 = Button(menu, text='Make Deposit', width=15, height=2).pack(pady=5)
btn_2 = Button(menu, text='Withdrawal', width=15, height=2).pack(pady=5)
btn_3 = Button(menu, text='Accounts', width=15, height=2).pack(pady=5)
btn_4 = Button(menu, text='Balance', width=15 ,height=2).pack(pady=5)
btn_5 = Button(menu, text='Exit', width=15, height=2).pack(pady=5)
root.mainloop()
提前感谢您的帮助
【问题讨论】:
-
您需要将打开Toplevel的函数传递给按钮的
command选项。