Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 10th, 2012, 02:31 AM
mrronoah mrronoah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 11 mrronoah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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()

Reply With Quote
  #2  
Old December 10th, 2012, 08:03 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 37 m 52 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old December 10th, 2012, 02:29 PM
mrronoah mrronoah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 11 mrronoah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old December 10th, 2012, 02:34 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 37 m 52 sec
Reputation Power: 383
I have no experience with pyserial.

Last edited by b49P23TIvg : December 10th, 2012 at 02:35 PM. Reason: Not a command!

Reply With Quote
  #5  
Old December 10th, 2012, 09:08 PM
mrronoah mrronoah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 11 mrronoah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 5 sec
Reputation Power: 0
Ok thanks anyway

Reply With Quote
  #6  
Old December 12th, 2012, 01:09 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 480 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 57 sec
Reputation Power: 63
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python functions help.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap