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
As set the selection value will be set before the window appears (selection = 0
).
If you want to run tests after mainloop()
, selection = var.get()
should also be after mainloop()
with tests.
If you do not want to close the master window before tests, use command=function
:
from Tkinter import *
def function():
selection = var.get()
if selection == 1:
# Default
elif selection == 2:
# User-defined
else:#selection==0
#No choice
master.quit()
master = Tk()
var = IntVar()
Label(master, text = "Select OCR language").grid(row=0, sticky=W)
Radiobutton(master, text = "default", variable = var, value = 1).grid(row=1, sticky=W)
Radiobutton(master, text = "user-defined", variable = var, value = 2).grid(row=2, sticky=W)
Button(master, text = "OK", command = function).grid(row=3, sticky=W)
mainloop()