python-tkslider/slider2json.py

45 lines
1.2 KiB
Python
Raw Permalink Normal View History

2019-08-01 22:19:58 +00:00
from Tkinter import *
import time
import json
class PrettyFloat(float):
def __repr__(self):
return '%.15g' % self
class App():
def __init__(self):
self.root = Tk()
self.label = Label(text="")
self.label.pack()
self.w1 = Scale(self.root, from_=1000, to=1)
self.w1.pack()
self.w2 = Scale(self.root, from_=1000, to=1)
self.w2.pack()
self.w3 = Scale(self.root, from_=1000, to=1)
self.w3.pack()
self.w4 = Scale(self.root, from_=1000, to=1)
self.w4.pack()
self.update_clock()
self.root.mainloop()
def update_clock(self):
velocity = float(self.w1.get())/1000
expressivity = float(self.w2.get())/1000
sensibility = float(self.w3.get())/1000
beauty = float(self.w4.get())/1000
data = {'velocity':PrettyFloat(velocity), 'expressivity':PrettyFloat(expressivity),'sensibility':PrettyFloat(sensibility),'beauty':PrettyFloat(beauty)}
print( data )
with open('/tmp/ws.json', 'w') as outfile:
json.dump(data, outfile)
now = time.strftime("%H:%M:%S")
self.label.configure(text=now)
self.root.after(1000, self.update_clock)
app=App()