Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x if-else条件查询中的GUI编程_Python 3.x - Fatal编程技术网

Python 3.x if-else条件查询中的GUI编程

Python 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

我目前正在学习python编程语言。我想知道如何调用GUI,例如按钮或Radiobutton inside if条件

此示例可能会让您有所了解。尝试将变量'need_btn'设置为True和False

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()