The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Python functions help.
Discuss Python functions help. in the Python Programming forum on Dev Shed. Python functions help. Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 10th, 2012, 02:31 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 11
Time spent in forums: 1 h 36 m 5 sec
Reputation Power: 0
|
|
|
Python functions help.
So i am making a slider that changes the value automatically.
so i have code that you can move the slider but it only prints the value at the very start. I want it to repeat the print function every second or half a second.
I'm assuming i need the print in a seperate function but when i put it at the top the w.get() hasnt been defined. Im kinda confused.
This is my current code:
Code:
from Tkinter import *
import time
root = Tk()
w = Scale(root, from_=0, to=100)
w.pack()
print w.get()
root.mainloop()
|

December 10th, 2012, 08:03 AM
|
 |
Contributing User
|
|
|
|
Code:
# online tkinter reference
# http://effbot.org/tkinterbook/radiobutton.htm
# (I found the information John Grayson's Python and Tkinter Programming.)
import Tkinter # from module import * is nasty.
root = Tkinter.Tk()
w = Tkinter.Scale(root, from_=0, to=100)
w.pack()
def show_slider(root,w):
millisecond = 1 # (to show the units)
print(w.get())
root.after(1000*millisecond,show_slider,root,w) # must re-install itself
show_slider(root,w)
root.mainloop()
__________________
[code] Code tags[/code] are essential for python code!
|

December 10th, 2012, 02:29 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 11
Time spent in forums: 1 h 36 m 5 sec
Reputation Power: 0
|
|
Thank you! I am actually using pyserial to write it to the serial port. I thought it was going to be as easy as changing print(wget()) to the serial function but its not. Any ideas?
Otherwise thank you anyway 
|

December 10th, 2012, 02:34 PM
|
 |
Contributing User
|
|
|
|
|
I have no experience with pyserial.
Last edited by b49P23TIvg : December 10th, 2012 at 02:35 PM.
Reason: Not a command!
|

December 10th, 2012, 09:08 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 11
Time spent in forums: 1 h 36 m 5 sec
Reputation Power: 0
|
|
Ok thanks anyway 
|

December 12th, 2012, 01:09 PM
|
 |
Contributing User
|
|
|
|
Another example:
Code:
''' tk_scale102.py
explore Tkinter's Scale (slider) widget response
'''
# for Python3 replace Tkinter with tkinter
import Tkinter as tk
def show_position(value):
"""show slider position in the window title"""
# you can use value which gives <type 'str'> or
# scale.get() gives <type 'int'>
s = "position = %s" % scale.get()
root.title(s)
root = tk.Tk()
# use width x height + x_offset + y_offset (no spaces!)
root.geometry("350x100+30+30")
# create a horizontal scale/slider with values
# from 0 to 100 sliding in steps of 1
scale = tk.Scale(root,
label="move slider:",
from_=0,
to=100,
resolution=1,
command=show_position,
orient='horizontal',
length=300)
scale.pack(side='left', expand='yes', fill='y')
root.mainloop()
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|