Tkinter tools - there are many tools in tkinter like messagebox,check button,radio button,frame,label,adding image to button with imagetk etc.
and we learn adding command with a button
Using messagebox in tkinter window
TYPE
note first of all we will import a package name massagebox
How to import - Type at upper like this -
from tkinter import messagebox as msg - as msg now we can use messagebox as msg like
type at lower-
note there are many messagebox function like- msg.showinfo(),msg.showwarning(),
showerror(), askokcancel(), askyesno(), askyesnocancel(),
askquestion() and askretrycancel() now see use of all and how it looks
msg.showinfo("error","you click the button") - ("title","message you want to show")
msg.showwarning("error","you click the button") - ("title","message you want to show")
msg.showerror("error","you click the button") - ("title","message you want to show")
msg.askokcancel("error","you click the button") - ("title","message you want to show")
msg.askyesno("error","you click the button") - ("title","message you want to show")
msg.askyesnocancel("error","you click the button") - ("title","message you want to show")
msg.askquestion("error","you click the button") - ("title","message you want to show")
msg.askretrycancel("error","you click the button") - ("title","message you want to show")
Using check button in tkinter window
TYPE
btn=Checkbutton(root,text="click").pack() - btn is name Checkbutton is function (where you want to place, text) .pack to see result
Using frame in tkinter window
TYPE
f1=Frame(root).pack() - f1 is name frame is function (where you wnt to place) .pack() to pack with tkinter window
Using label in tkinter window
TYPE
la=Label(f1,text="first frame").pack() - la is name of label (where you want to place I place it in f1 frame ,text)
note first letter of Label is capital
Using image on button in tkinter window note you can add only png file in this method
and the image you want to add is always in your that folder where your main.py file
TYPE
type this -
mango = PhotoImage(file="hu.png") - mango is name of it like a variable PhotoImage is function(file="your full file name")
make a button -
btn=Button(root,image=mango).pack() - Button is function (where you want to place,image=your image variable)
Using radio button in tkinter window
TYPE
var = IntVar() - first make a int variable
R1=Radiobutton(root, text="Option 1", variable=var, value=1).pack() - R1 in name Radiobutton is function
(where you want to place,text="you want" ,variable="your int ariable name",value=1)
R2=Radiobutton(root, text="Option 2", variable=var, value=2).pack() - R2 in name Radiobutton is function
(where you want to place,text="you want" ,variable="your int ariable name",value=2)
note* - always value is 1 then 2 then 3 etc.
if you set same value it select all radio button
to be continued...(adding jpeg images, reading data from button, full use of .pack() etc )
No comments:
Post a Comment