Python Forum
How to instantly update the plot by getting values from a Scale widget?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to instantly update the plot by getting values from a Scale widget?
#3
(May-16-2022, 02:40 AM)menator01 Wrote: You might can use this approach

import tkinter as tk

class Window:
    def __init__(self, parent):
        self.slidervar = tk.IntVar()
        self.slider = tk.Scale(parent, from_=1, to=10, orient='horizontal')
        self.slider['variable'] = self.slidervar
        self.slider.pack()

        self.button = tk.Button(parent)
        self.button['text'] = 'Open Window'
        self.button.pack()


class TopWindow:
    def __init__(self):
        window = tk.Toplevel(None)
        window.geometry('200x200+500+300')
        self.label = tk.Label(window)
        self.label.pack()

class Controller:
    def __init__(self, window):
        self.window = window

        self.window.button['command'] = self.openwindow
        self.window.slider['command'] = self.update

    def openwindow(self):
        self.topwindow = TopWindow()
        self.topwindow.label['text'] = self.window.slidervar.get()

    def update(self, event):
        self.topwindow.label['text'] = self.window.slidervar.get()

if __name__ == '__main__':
    root = tk.Tk()
    root.geometry('200x200+250+250')
    Controller(Window(root))
    root.mainloop()

Thanks for your reply. Actually, I am a little bit new to tkinter. I remember I could show the values got from the slider in a wop-level window. But updating the plot instantly was my main problem. besides that, I don't really want to change my classes.
Reply


Messages In This Thread
RE: How to instantly update the plot by getting values from a Scale widget? - by OLE - May-16-2022, 05:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Update exist plot while change upper limit or lower limit SamLiu 1 1,648 Feb-05-2023, 10:09 AM
Last Post: SamLiu
Exclamation Update Point Coordinates from Mouse Event in a Plot Jguillerm 2 2,156 Jan-10-2023, 07:53 AM
Last Post: Jguillerm
  [Tkinter] how to draw dynamic moving scale and potting trace point on waveform in tkinter pytho sameer_1985 0 2,555 May-31-2020, 01:52 PM
Last Post: sameer_1985
  [Tkinter] Update matplotlib plot correctly Particledust 0 5,248 Apr-20-2020, 04:59 PM
Last Post: Particledust
  [Tkinter] Scale at the Top Friend 5 4,121 Jul-20-2019, 05:02 PM
Last Post: Yoriz
  Update plot by <Return> bind with entry widget Zorro 1 4,991 Mar-09-2019, 12:27 PM
Last Post: Zorro
  [Tkinter] update the content of Text widget atlass218 10 18,975 Dec-15-2018, 11:51 AM
Last Post: atlass218
  [Tkinter] Update value in Entry widget dannyH 7 31,734 Apr-02-2017, 10:12 AM
Last Post: dannyH
  [Tkinter] Resetting scale value back to 0 after the slider loses focus lwhistler 3 8,196 Mar-07-2017, 10:01 PM
Last Post: Larz60+
  Bokeh - dynamic update widget.Select values sixteenornumber 0 10,905 Dec-28-2016, 02:15 PM
Last Post: sixteenornumber

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020