0

I have a button which recalls 24 values from a text file. I now want to recall these values using a tkinter Scale widget but obviously I will want these values to increase in increments of 1 up to the value that is stored in the text file, these values will all be different.

So, for example, a shortened version of my text file is:

C1=255
C2=254
C3=120
C4=60
C5=153

So at the minute, my button will instantly recall these values, but I no want to slowly increment all of them using a scale so that when the scale is at the top of its travel it will represent all of the numbers shown above.

Here is my code which will do what I want but using a button, I now need to change the button for a slider:

from Tkinter import *

master= Tk()
master.geometry('500x500+0+0')

def print_value(val):
    print ("c1="+str (c1v.get()))
    print ("c2="+str(c2v.get()))

c1v=DoubleVar()
c2v=DoubleVar()

c1 = Scale(master, from_=255, to=0, length =400,width =100, troughcolor = 'blue',command=print_value, variable =c1v)
c1.grid(row=1,column=1)
c2 = Scale(master, from_=255, to=0, length =400,width =100, troughcolor = 'blue',command=print_value, variable =c2v)
c2.grid(row=1,column=2)

def load_p1():
    pass
    lp1 = open("/home/pi/Desktop/IEP/test/preset_test.txt")
    val1, val2 = (x.split("=")[1] for x in lp1)
    c1.set(val1)
    c2.set(val2)
    lp1.close()

def record():
    save_path = '/home/pi/Desktop/IEP/test'
    name_of_file = ("preset_test")
    completeName = os.path.join(save_path, name_of_file+".txt")
    file1 = open(completeName , "w")
    toFile = ("c1="+str (c1.get())+ "\n""c2="+str(c2.get()))
    file1.write(toFile)
    file1.close()

rec=Button(master, text="Record",width=20, height=10, bg='Red', command=record)
rec.grid(row=2, column=1)

load=Button(master, text="Load",width=20, height=10, bg='gold',command=load_p1)
load.grid(row=2, column=2)

master.mainloop()
finefoot
  • 9,914
  • 7
  • 59
  • 102
user2996828
  • 1,137
  • 3
  • 12
  • 19
  • 1
    Please post the code of your scale so we can see and modify. It makes your question clearer. – User Feb 08 '14 at 19:23
  • I'm having a hard time understanding what you're trying to do. The phrase "recall these values using a tkinter scale" makes no sense to me. When you say "I no want to slowly increment all of them..." does that mean you want an animation where the scale slowly moves from zero to the values? If you have 5 numbers in the file, does that mean you want five scales? – Bryan Oakley Feb 11 '14 at 15:00

1 Answers1

0

The best place to start is to find a tkinter tutorial and learn the basics of tkinter, completely ignoring the problem you are trying to solve. Then, using what you've learned, try to solve your problem. When you get stuck on a specific problem come back here and show us what you've tried.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • I already have a detailed understanding of tkinter that's what I've used to build my GUI, I'm just after how I would control multiple scales from one scale but in a way that represented the different values like the ones above. – user2996828 Feb 10 '14 at 10:29
  • I've posted it as an answer as I never know how to format code in the comments – user2996828 Feb 10 '14 at 23:10
  • @user2996828: the appropriate thing to do is to edit your original question. Answers are for answers, not for extended discussions. – Bryan Oakley Feb 10 '14 at 23:21
  • Ah ok well i have done that now and deleted the other post, any ideas how i can do this? – user2996828 Feb 11 '14 at 14:49