Python 3.x if-else条件查询中的GUI编程
我目前正在学习python编程语言。我想知道如何调用GUI,例如按钮或Radiobutton inside if条件 此示例可能会让您有所了解。尝试将变量'need_btn'设置为True和FalsePython 3.x if-else条件查询中的GUI编程,python-3.x,Python 3.x,我目前正在学习python编程语言。我想知道如何调用GUI,例如按钮或Radiobutton inside if条件 此示例可能会让您有所了解。尝试将变量'need_btn'设置为True和False import tkinter as tk class App(tk.Frame): def
import tkinter as tk
class App(tk.Frame):
def __init__(self, master=None, hibtn=True):
tk.Frame.__init__(self, master)
self.pack()
self.createWidgets(hibtn=hibtn)
def createWidgets(self, hibtn=True):
if hibtn:
self.btn = tk.Button(self)
self.btn["text"] = "Hello\n(click me)"
self.btn["command"] = self.say_hi
self.btn.pack()
self.ext = tk.Button(self, text="Exit", command=root.destroy)
self.ext.pack()
def say_hi(self):
print("hi from Tkinter!")
root = tk.Tk()
need_btn = False
# need_btn = True
if need_btn:
app = App(master=root)
else:
app = App(master=root, hibtn=False)
app.mainloop()