In this article, I will make a simple example application of the radiobutton in Python. In this example, I will disable the entry by using a radiobutton.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry("380x70+200+50") # size of the window
root.title("https://pythonprogrammingworld23.blogspot.com/") # adding a title
def config():
print(rb_variable.get())
if rb_variable.get():
e1.config(state='normal') #normal
else:
e1.config(state='disabled')
rb_variable=tk.BooleanVar()
e1 = tk.Entry(root,font=("arial,12,normal"))
e1.insert(8, "Hi! Bahadir")
e1.grid(row=1,column=1,padx=10,pady=10)
rb_variable.set(True)
rb1 = tk.Radiobutton(root, text='Enable', variable=rb_variable,
value=True,command=config,font=("arial,12,normal"))
rb1.grid(row=1,column=2)
rb2 = tk.Radiobutton(root, text='Disable', variable=rb_variable,
value=False,command=config,font=("arial,12,normal"))
rb2.grid(row=1,column=3)
root.mainloop() # keep the window open
Figure 1
Figure 2
I have come to the end of this article. See you in my next article. Happy coding. Bahadir Sahin
No comments:
Post a Comment