Python tkinter scale

Displaying a scale .
Basics of Python Tkinter
import tkinter as tk 
my_w = tk.Tk()
my_w.geometry("200x200") 
my_w.title("Scale")
l1=tk.Label(my_w,text="Scale")
l1.grid(row=1,column=1)

my_scale = Scale(my_w, from_=0, to=100, orient=HORIZONTAL)
my_scale.grid(row=2,column=1) 

my_w.mainloop()
Scale Tkinter
Reading value of a scale using get()
my_scale.get()
Setting value of a scale using set()
my_scale.set()

Copy value from one scale to other by button click

By using a button click we will assign the value of 2nd scale by reading value of 1st.
Read and set value of Scale
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("500x500") 

def my_upd():
    my_scale2.set(my_scale1.get()) # read and set value 
    
my_scale1 = Scale(my_w, from_=0, to=100, orient=HORIZONTAL)
my_scale1.grid(row=1,column=1) 

my_scale2 = Scale(my_w, from_=0, to=100, orient=HORIZONTAL)
my_scale2.grid(row=3,column=1) 

b1 = tk.Button(my_w, text='Copy', width=10,command=lambda: my_upd())
b1.grid(row=2,column=1) 

my_w.mainloop()

Direct Copy from one Scale to other without any button click

On move copy data from Scale
import tkinter as tk
from tkinter import *
my_w = tk.Tk()
my_w.geometry("300x200") 

def my_upd(value):
    my_scale2.set(my_scale1.get())
        
my_scale1 = Scale(my_w, from_=0, to=100, orient=HORIZONTAL,command=my_upd)
my_scale1.grid(row=1,column=1) 

my_scale2 = Scale(my_w, from_=0, to=100, orient=HORIZONTAL)
my_scale2.grid(row=3,column=1) 

my_w.mainloop()
  1. Exercise on Scale
Solution



plus2net.com



Post your comments , suggestion , error , requirements etc here




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