1. scale scroll bar
import tkinter as tk window = tk.Tk() window.title("The window") window.geometry("400x300") l = tk.Label(window,bg='yellow',text='empty') l.pack() def print_selection(v): #The parameter v here is the data of the scroll bar positioning #config Modify the content in text l.config(text='you have selected ' + v) #slider scale, the name of the label scale widget, from_ to slide from 1 to 20 value range, # orinent tk.HORIZONTAL here is to set the scroll bar at ease, for the horizontal #resolution 0.01 keep several decimal places and keep 2 places #showvalue 0 does not display numbers 1 displays numbers, what is the interval of tickinterval 2 s = tk.Scale(window,label='try me',from_=1,to=11,orient=tk.HORIZONTAL, length=400,showvalue=1,tickinterval=2,resolution=0.01,command=print_selection) s.pack() window.mainloop ()
2、Checkbutton
#checkbutton Check option import tkinter as tk window = tk.Tk() window.title("The window") window.geometry("400x300") l = tk.Label(window,bg='red',width=20,text='empty') l.pack() def print_selection(): if(var1.get() == 1) & (var2.get() == 0): l.config(text="I love only python ") elif(var1.get() == 0) & (var2.get() == 1): l.config(text="I love only C++ ") elif(var1.get() == 0) & (var2.get() == 0): l.config(text = "I do not love either") else: l.config(text='I love both') var1 = tk.IntVar () var2 = tk.IntVar () #Create a checkbutton component, the parameter onvalue is similar to the value in the radiobutton component mentioned earlier, #When we select this checkbutton, the value of onvalue 1 will be put into var1, and then var1 will assign it to the parameter variable, The usage of #offvalue is similar, but offvalue is when the checkbutton is not selected, the value of offvalue 1 is put into var1, #Then assign it to the parameter variable This is to create a checkbutton component, and so on, you can create multiple checkbuttons c1 = tk.Checkbutton(window,text='Python',variable=var1,onvalue=1,offvalue=0, command=print_selection) c1.pack() c2 = tk.Checkbutton(window,text='C++',variable=var2,onvalue=1,offvalue=0, command=print_selection) c2.pack() window.mainloop ()