Python Forum
How to change a tkinter label with scale and how to save that new value for later?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change a tkinter label with scale and how to save that new value for later?
#1
I've been building and ROV for a while now and made a pretty sweet GUI first with Arduino IDE, then with MATLAB, everything worked great. I upgraded to a Raspberry Pi 5 and now I want to make the same GUI with python but I'm pretty new with python, so bear with me.

Here's what I want to do and nothing I can think of is fixing the problem, my code is below. I want to have a tkinter scale from 0 to 100, then I want to convert those values to a pwm signal, so 1100 to 1900. I have five sliders that all do the same thing, one light intensity, forward thrust, reverse thrust, ascend, and descend thrust. As you adjust the slider I want a label that notifies the user on how fast they are going. These values are meant to be limits for the thruster, so if you set the scale to 80 its converted to a pwm signal of 1740 and now the forward thrusters can only recieve a pwm signal of 1500 to 1740 . Hopefully all of that makes sense.

Here's the problem, I have my labels set to specific values of the slider, when I slide back and forth the labels show up but I cant them to go away when the value changes. Instead they overall and I cant figure out how to get rid of them. I'll figure out the rest of these things later. Any ideas? Thanks!

       def ascend_thruster_modification(self):
               thrust_mid = 1500
               thrust_ascend_var = round(ascend_scale_int.get())
               new_thrust_ascend_var = (thrust_ascend_var/100)*400
               final_thrust_forward_var = new_thrust_ascend_var + thrust_mid

              if thrust_ascend_var == 0:
                    forward_label1 = ttk.Label(vic_settings_frame, text = 'Off')
                    forward_label1.place(relx = .24, rely = .23)
         
              if 1 <= thrust_ascend_var <= 50:
                    forward_label1 = ttk.Label(vic_settings_frame, text = 'Low Speed')
                    forward_label1.place(relx = .24, rely = .23)

              if 51 <= thrust_ascend_var <= 75:
                    forward_label1 = ttk.Label(vic_settings_frame, text = 'High Speed')
                    forward_label1.place(relx = .24, rely = .23)

              if thrust_ascend_var >= 76:
                    forward_label1 = ttk.Label(vic_settings_frame, text = 'Maximum Speed')
                    forward_label1.place(relx = .24, rely = .23)

    forward_scale_int = tk.IntVar(value = 100)
    thrust_forward_scale = ttk.Scale(vic_settings_frame, from_ = 0, to = 100, length = 300, orient = 'horizontal', variable = forward_scale_int, command = forward_thruster_modification)
    
    forward_text = ttk.Label(vic_settings_frame, text = 'Forward Thruster Speed Settings')
    forward_label = ttk.Label(vic_settings_frame, text = 'Current Forward Thruster Speed: ')

    forward_text.place(relx = .03, rely = .16)
    forward_label.place(relx = .03, rely = .23)
    thrust_forward_scale.place(relx = .03, rely = .19)  
idk why but some of my indentations are weird and I cant figure out how to change them. The labels and scale bar are not part of the function. All of this is part of a larger function. Thanks!
Reply


Messages In This Thread
How to change a tkinter label with scale and how to save that new value for later? - by bkeith - Jun-27-2024, 05:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 677 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 1,125 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  change directory of save of python files akbarza 3 1,172 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  How to properly scale text in postscript conversion to pdf? philipbergwerf 3 1,321 Nov-07-2022, 01:30 PM
Last Post: philipbergwerf
  KeyError: 0 when trying to dedupe and match records at scale Catalytic 1 2,359 Apr-07-2022, 06:34 PM
Last Post: deanhystad
  Matplotlib scale julienhofmann 0 1,912 Apr-04-2021, 08:50 AM
Last Post: julienhofmann
  OOP Label In Tkinter Harshil 2 2,036 Aug-21-2020, 07:14 PM
Last Post: bowlofred
  Not able to update y2 axis scale in plotly ankitawadhwa 0 2,034 Jan-27-2020, 06:44 PM
Last Post: ankitawadhwa
  Change the scale on a Matplotlib Interactive Graph khatharsis 0 2,986 Oct-13-2019, 06:14 AM
Last Post: khatharsis
  How to manually define color bar scale in seaborn heatmap SriRajesh 3 18,736 Sep-08-2019, 11:12 AM
Last Post: RudraMohan

Forum Jump:

User Panel Messages

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