Radio button values in Python Tkinter

后端 未结 3 1665
陌清茗
陌清茗 2021-01-14 18:10

I am trying to create a dialog box in Python using Tkinter. The goal is to have a dialog box with two radio buttons and an \"OK\" button. Radio button one selects the opti

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 18:43

    Instead of directly using master.quit in the Button's command, define a function that finishes up the program then calls master.quit():

    def end_program(event=None):#event will let it be used as .bind callbacks too if you need it.
        selection = var.get()
        if selection:
            NotImplemented
        else:
            NotImplemented
        master.quit()
    
    ...
    
    Button(master, text = "OK", command = end_program).grid(row=3, sticky=W)
    

    one the master is closed some of the data from the widgets is cleaned up so master.quit() needs to be called only after you are done accessing the widgets.

提交回复
热议问题