Aug-10-2021, 06:59 PM
hello i have a problem with radiobutton. I would like to have the following effect:
1. All radio buttons should be unchecked at the start.
2. When I mark 'OK' and press 'PRESS' in the text window 'OK' should appear - and it works
3. Same with 'OV' and 'RE' - it works.
4. When I click on 'Other' the 'Entry' field becomes active and when I enter for example 'XX' there and press 'Press' in the 'Text' field 'XX' should appear.
Unfortunately option 4 does not work, I tried to set it by variable somehow but I fail.
I would be grateful for your suggestions.
1. All radio buttons should be unchecked at the start.
2. When I mark 'OK' and press 'PRESS' in the text window 'OK' should appear - and it works
3. Same with 'OV' and 'RE' - it works.
4. When I click on 'Other' the 'Entry' field becomes active and when I enter for example 'XX' there and press 'Press' in the 'Text' field 'XX' should appear.
Unfortunately option 4 does not work, I tried to set it by variable somehow but I fail.
I would be grateful for your suggestions.
import tkinter as tk
from tkinter import *
def initWindow():
root = tk.Tk()
root.geometry('500x260')
return root
root = initWindow()
var = tk.StringVar()
def change1():
field_Rest.config(state='normal')
def change2():
field_Rest.delete(0,END)
field_Rest.config(state='disabled')
def click_1():
field_result.delete(1.0, END)
field_result.insert(1.0, var.get())
bplick = tk.Button(root,text='Press', width=5, command=click_1)
bplick.place(x=340,y=10)
field_Rest = Entry(root, width=4,state='disabled')
field_Rest.place(x=230,y=10)
chbRE = tk.Radiobutton(root,text='RE',variable=var, value='RE', command=change2)
chbRE.place(x=20,y=10)
chbOK = tk.Radiobutton(root,text='OK',variable=var, value='OK', command=change2)
chbOK.place(x=70,y=10)
chbOV = tk.Radiobutton(root,text='OV',variable=var, value='OV', command=change2)
chbOV.place(x=120,y=10)
x2 = str(field_Rest.get())
print(x2)
chbOther = tk.Radiobutton(root,text='Other',variable=var, value=str(x2), command=change1)
chbOther.place(x=170,y=10)
field_result = Text(root, width=25, height=10)
field_result.place(x=50,y=45)
root.mainloop()
