Tkinter Quick Reference

import tkinter as tk
my_w = tk.Tk()
my_w.geometry("500x500")  # Size of the window 
my_w.title("www.plus2net.com")  # Adding a title
my_w.mainloop()  # Keep the window open
Entry e1 e1=tk.Entry(my_w,text='plus2net',font=24)
e1.get() to read entries
e1.delete(0,end) to remove entries
textvariable=StringVar() To read or update user entries
Button b1b1=tk.Button(my_w,text=’My Button’,width=10,bg=’green’)
command=lambda:my_function() to add click event
w=b1.cget(‘width’) width of the button
state= normalactive or disabled
relief =raised , sunken ,flatridgesolid & groove Border style
Checkbutton c1_v1=tk.StringVar()
c1 = tk.Checkbutton(my_w, text='PHP', variable=c1_v1,
onvalue='Yes',offvalue='No',command=my_upd)
c1_v1.get() Read the value
c1_v1.set(‘No) Set the value
Radiobutton r1_v = tk.StringVar()
r1_v.set('Passed') Set the value or select the radio button by default
r1 = tk.Radiobutton(my_w, text='Passed', variable=r1_v, value='Passed',command=my_upd)
r2 = tk.Radiobutton(my_w, text='Failed', variable=r1_v, value='Failed',command=my_upd)
Comboboxsel=tk.StringVar()
cb1 = ttk.Combobox(my_w, values=months,width=7,textvariable=sel)
cb1.get() Value of the selected option
cb1.current() index of the current selection
cb1.delete(0,'end') Clear the selection
cb1['values'] +=('my new',) Adding option
state=active, normal, disabled
Labelfont1=[‘Times’,28,’underline’]
my_str = tk.StringVar()
l1 = tk.Label(my_w, textvariable=my_str, width=10,font=font1,bg='yellow', anchor='center' )
my_str.get() Read the Label
my_str.set(‘Welcome’) Update the text
relief=raised, sunken, ridge, solid,flat, groove
Text t1 = tk.Text(my_w, height=1, width=20,bg='yellow')
my_str=t1.get("1.0",'end-1c') Read the entry
t1.insert(tk.END, my_str) Insert text
Treeview trv=ttk.Treeview(my_w,selectmode='browse')
trv["columns"]=("1","2")
trv['show']='headings'
trv.column("1",width=30,anchor='c')
trv.column("2",width=80,anchor='c')
trv.heading("1",text="id")
trv.heading("2",text="Name")
i=1
trv.insert("",'end',iid=i, values=(i,'Alex') )
Progressbar prg1 = ttk.Progressbar(my_w,orient = HORIZONTAL,value=70,length = 300,mode = 'determinate')
prg1['value'] =80 Update the value or read the value
Spinbox t1 = StringVar()
sb1 = Spinbox(my_w, from_= 0, to = 10,width=5,textvariable=t1)
t1.set(8) Update
t1.get() Read
StringVar() str1=tk.StringVar(value='Option 1')
str1.set(‘Option 2’) Update
str1.get() Read
str1.trace_add('write',my_upd)
Events
Message Box
Layout

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer