Tkinter Message and Radiobutton in Python

Hello friends how are you, today in this blog i will teach you what is Message and Radiobutton, syntax of Message and Radiobutton, how to create Message and Radiobutton, how Message and Radiobutton work in a very simple way.

Let's start 

Message

  • Message is used to display multiline text to the user.
  • It can't be edited.
  • Syntax:
    m = Message ( master, option1,option2, ... )
    
  • Here master is parent window and option can be used as a key-value pairs.
  • Examples of options are bg,font,width,height etc.

from tkinter import *
top = Tk()
top['bg']="#51E1DC"
top.geometry("200x150")
#create message
msg = Message( top, text = "I love Python Program").pack()
top.mainloop()

 



 Radiobutton

  • We can create many radio buttons using tkinter Radiobutton.
  • It is used for selection purpose.
  • We can select only one option from many options.
  • Syntax:
    r = Radiobutton ( master, option1,option2, ... )
    
  • Here master is parent window and option can be used as a key-value pairs.
  • Examples of options are bg,font,width etc.

from tkinter import *
top = Tk()
#window dimension
top.geometry("300x180")
top['bg']="#51E1DC"
rdb=IntVar()
Label(top,text="Select Gender").pack()
Radiobutton(top, text="Male", variable=rdb, value=1).place(x=50,y=20)
Radiobutton(top, text="Female", variable=rdb, value=2).place(x=50,y=50)
Radiobutton(top, text="Other", variable=rdb, value=3).place(x=50,y=80)
top.mainloop()
 


from  tkinter import  messagebox
from tkinter import *
top = Tk()
#window dimension
top.geometry("300x180")
top['bg']="#51E1DC"
def myFun():
    if (rdb.get() == 1):
        messagebox.showinfo("Result", "You selected Male")
    if (rdb.get() == 2):
        messagebox.showinfo("Result", "You selected Female")
    if (rdb.get() == 3):
        messagebox.showinfo("Result", "You selected Other")
rdb=IntVar()
Label(top,text="Select Gender").pack()
#create Radio Buttons
Radiobutton(top, text="Male", variable=rdb, value=1,command=myFun).place(x=50,y=20)
Radiobutton(top, text="Female", variable=rdb, value=2,command=myFun).place(x=50,y=50)
Radiobutton(top, text="Other", variable=rdb, value=3,command=myFun).place(x=50,y=80)
top.mainloop()



Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks.😊

Post a Comment

0 Comments