-4
我目前正在學習python編程語言。我想知道如何調用GUI,例如Button或Radiobutton,如果條件。請幫我GUI程序內部if-else條件查詢
我目前正在學習python編程語言。我想知道如何調用GUI,例如Button或Radiobutton,如果條件。請幫我GUI程序內部if-else條件查詢
這個樣本可能會給你一些想法。嘗試將變量'need_btn'設置爲True並且假設
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()
https://wiki.python.org/moin/GuiProgramming – Idos