【发布时间】:2020-07-09 05:01:08
【问题描述】:
import Tkinter as tk
import webbrowser
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
def Alberta():
webbrowser.open_new(r"https://news.google.com/covid19/map?hl=en-CA&mid=%2Fm%2F0j95&gl=CA&ceid=CA%3Aen")
def BC():
webbrowser.open_new(r"https://news.google.com/covid19/map?hl=en-CA&mid=%2Fm%2F015jr&gl=CA&ceid=CA%3Aen")
print(" Enter 1 for Alberta \n Enter 2 for BC \n ")
user_input= input() # type: int
if user_input==1:
lab= tk.Label(root,bg="yellow", text="Alberta")
lab.pack()
button = tk.Button(frame,
fg="red",
command=Alberta)
button.pack(side=tk.LEFT)
elif user_input==2:
button = tk.Button(frame,
fg="red",
command=BC)
lab = tk.Label(root, text="British Columbia")
lab.pack()
button.pack(side=tk.LEFT)
else:
print("Invalid input! Try Again!")
root.geometry('300x400')
root.mainloop()
【问题讨论】:
-
避免将控制台输入与 GUI 应用程序混合。 “我似乎无法按照我的意愿编辑和格式化按钮” 是什么意思?
标签: python button tkinter pycharm