I created a simple program with 2 radio buttons, Option-1 and Option-2 respectively.
By default, Option-1 is selected and the label "You selected Option 1"
is displayed.
During the runtime, if the user selects Option-2, then the label "You selected Option 2"
should be displayed.
With this requirement, I created the program below. But is not working. There is no response after I select Option-2 radio button.
My code is given below.
Can any of you solve my issue ?
import tkinter as tk
class window1:
def __init__(self, master):
self.master = master
self.frame1 = tk.Frame(self.master, width=300, height=100)
self.frame1.place(x=5, y=5)
window1.priority = tk.IntVar(value=1)
def message_radio(self):
if self.priority.get() == 1:
Message1 = tk.Label(self.frame1, text="You selected Option 1").place(x=10, y=35)
else:
Message2 = tk.Label(self.frame1, text="You selected Option 2").place(x=10, y=35)
def radio_button(self):
radiobutton1 = tk.Radiobutton(self.frame1, text="Option 1", variable=self.priority,
value=1,command=window1.message_radio(self))
radiobutton1.place(x=10, y=10)
radiobutton2 = tk.Radiobutton(self.frame1, text="Option 2", variable=self.priority,
value=2,command=window1.message_radio(self))
radiobutton2.place(x=175, y=10) def main():
def main():
root = tk.Tk()
root.geometry( "300x100" )
app = window1( root )
app.radio_button()
root.mainloop()
if __name__ == '__main__':
main()