Python Forum
problem with radio button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with radio button
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.

import tkinter as tk
from tkinter import *

def initWindow():
    root = tk.Tk()
    return root

root = initWindow()

var = tk.StringVar() 

def change1():

def change2():

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),y=10)
field_Rest = Entry(root, width=4,state='disabled'),y=10)

chbRE = tk.Radiobutton(root,text='RE',variable=var, value='RE', command=change2),y=10)
chbOK = tk.Radiobutton(root,text='OK',variable=var, value='OK', command=change2),y=10)
chbOV = tk.Radiobutton(root,text='OV',variable=var, value='OV', command=change2),y=10)

x2 = str(field_Rest.get())

chbOther = tk.Radiobutton(root,text='Other',variable=var, value=str(x2), command=change1),y=10)

field_result = Text(root, width=25, height=10),y=45)

You need to grab the current value of field_rest at the point of clicking the button if the other checkbox is selected.

import tkinter as tk

def init_window():
    root = tk.Tk()
    return root

root = init_window()

var = tk.StringVar()

def change1():

def change2():
    field_rest.delete(0, tk.END)

def click_1():
    result = field_rest.get() if var.get() == "Other" else var.get()
    field_result.delete(1.0, tk.END)
    field_result.insert(1.0, result)

bplick = tk.Button(root, text="Press", width=5, command=click_1), y=10)
field_rest = tk.Entry(root, width=4, state="disabled"), y=10)

chb_re = tk.Radiobutton(root, text="RE", variable=var, value="RE", command=change2), y=10)
chb_ok = tk.Radiobutton(root, text="OK", variable=var, value="OK", command=change2), y=10)
chb_ov = tk.Radiobutton(root, text="OV", variable=var, value="OV", command=change2), y=10)

chb_other = tk.Radiobutton(
    root, text="Other", variable=var, value="Other", command=change1
), y=10)

field_result = tk.Text(root, width=25, height=10), y=45)

thank you, its working very correctly.
But what to do to make these 4 checkboxes unchecked when starting the program?
But it is more common to select a default instead of leaving a radio cluster empty. Replace None above with the default value.

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Is there a way to determine if a radio button has been selected? TWB 5 4,217 Jan-31-2023, 09:44 AM
Last Post: Vadanane
  [Tkinter] Radio Buttons Working Bassackwards gw1500se 6 2,190 Dec-07-2021, 07:13 PM
Last Post: menator01
  [Tkinter] Grid the radio buttons Joni_Engr 6 4,466 Nov-24-2021, 07:20 PM
Last Post: menator01
  Radio butto to enable/disable combo box in Tkinter cybertooth 5 5,249 Oct-09-2021, 07:30 AM
Last Post: cybertooth
  tkinter python button position problem Nick_tkinter 3 3,348 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  [Tkinter] Button click problem using OOP JohnB 5 3,409 Oct-21-2020, 12:43 PM
Last Post: JohnB
  [Tkinter] I can't get information from a radio button aquerci 2 2,649 May-20-2020, 10:31 AM
Last Post: aquerci
  Problem about image and button scotesse 5 2,767 Apr-27-2020, 10:09 AM
Last Post: scotesse
  Problem with Submit button Tkinter Reldaing 2 3,528 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa
  [PyQt] Problem how to click a button inside a group box? mart79 2 3,290 Aug-05-2019, 01:21 PM
Last Post: mart79

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020