I've been working on a tkinter project that uses three sliders to customize an RGB output. The code bellow works just fine:
from tkinter import*
Window = Tk()
Window.title("Edit Color")
Window.geometry('1270x680')
Window.configure(background = "black")
#sliders
Slider_1 = Scale(activebackground='pink',
orient=HORIZONTAL,
relief=GROOVE,
length = 500,
from_=0,to_=255,
bg='red',
tickinterval=51,
troughcolor='pink')
Slider_1.grid(row=0, column=0,padx=60, pady=70)
Slider_2 = Scale(activebackground='lightGreen',
orient=HORIZONTAL,
relief=GROOVE,
length = 500,
from_=0,to_=255,
bg='Green',
tickinterval=51,
troughcolor='lightGreen')
Slider_2.grid(row=2, column=0, pady=70)
Slider_3 = Scale(activebackground= 'light blue',
orient=HORIZONTAL,relief=GROOVE,
length = 500, from_=0, to_=255,
bg='blue',
tickinterval=51,
troughcolor= 'light blue')
Slider_3.grid(row=4, column=0, pady=70)
Window.mainloop()
Then I added two things in order to be able to print the values of the sliders. The first is near the top. It is a function which is associated with a parameter called ”command”, that can be found at the end of the parentheses of each slider function:
from tkinter import*
Window = Tk()
Window.title("Edit Color")
Window.geometry('1270x680')
Window.configure(background = "black")
def print_value(val):
print val
#sliders
Slider_1 = Scale(activebackground='pink',
orient=HORIZONTAL,
relief=GROOVE,
length = 500,
from_=0,to_=255,
bg='red',
tickinterval=51,
troughcolor='pink',command=print_value)
Slider_1.grid(row=0, column=0,padx=60, pady=70)
Slider_2 = Scale(activebackground='lightGreen',
orient=HORIZONTAL,
relief=GROOVE,
length = 500,
from_=0,to_=255,
bg='Green',
tickinterval=51,
troughcolor='lightGreen',command=print_value)
Slider_2.grid(row=2, column=0, pady=70)
Slider_3 = Scale(activebackground= 'light blue',
orient=HORIZONTAL,relief=GROOVE,
length = 500, from_=0, to_=255,
bg='blue',
tickinterval=51,
troughcolor= 'light blue',command=print_value)
Slider_3.grid(row=4, column=0, pady=70)
Window.mainloop()
When I added this and executed the program the screen was black and I had no Sliders.
what do I do?
创建滑块的代码位于函数print_value
,您永远不会调用print_value
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.