How to add Horizontal a Vertical Scale using tkinter
- On Raspberry pi Create a directory
- download test_slide and unzip it in that directory
- On Raspberry Pi under Menu Programming select Thonny Python IDE
- from menu file open file test_slide.py
- run the Python file
download: test_slider
;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #!/usr/bin/env python3 from tkinter import * import tkinter as tk from tkinter.font import Font from tkinter import messagebox import time win = tk.Tk() a5 = PhotoImage(file="g1.png") win.tk.call('wm', 'iconphoto', win._w, a5) win.title("Ardiotech Raspberry Pi Version 2.0") win.geometry("800x400+0+0") win.resizable(width=True, height=True) win.configure(bg='black') def exitProgram(): if messagebox.askyesno("Print", "Exit?"): win.destroy() originalPlantImage = tk.PhotoImage(file="exit.png") image = originalPlantImage.subsample(15, 15) exitb = tk.Button(win, text="Exit", image=image, font=("Helvetica", 14,'bold'), compound="left", borderwidth=3, width = 60, height = 30, bg="lightskyblue", fg='black', command= exitProgram, activebackground="dark gray") exitb.pack(fill=X,padx=2) def read_every_second(): g_value=random.randint(0,100) win.after(100, read_every_second) def updateCanvas(sliderVal): slider2.config(state="active") slider2.set(sliderVal) slider2.config(state="disabled") slider1 = Scale(win, from_=100, to=0, length=170, width=24, # tickinterval=10, orient=VERTICAL,#HORIZONTAL, relief=SUNKEN, bd=1, bg='black', highlightbackground = "royalblue", troughcolor='orange', activebackground="blue", fg= "white", font=("Helvetica", 8), highlightthickness=1, sliderlength = 30, sliderrelief=RAISED, command = updateCanvas) slider1.pack(side=LEFT,padx=10) slider2 = Scale(win, from_ = 100,to = 0, length = 170, width = 24, tickinterval = 10, orient = VERTICAL, relief = "sunken", bd=1, bg = "black", highlightbackground = "royalblue", troughcolor = "red", activebackground="red", fg= "white", font=("Helvetica", 8), highlightthickness=1, state = DISABLED, sliderlength = 30, sliderrelief=RAISED #label = "Temperature C", ) slider2.pack(side=LEFT,padx=10) #read_every_second() mainloop() |