#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Button dose something else depending on users input


    in tkinter how to i change what the button dose depend on a vaule the users inputed
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Run this program. The radio buttons select the action taken when you click the GO button. Modify this code to suit your need.
    Code:
    import string
    
    try:
        import tkinter
    except:
        import Tkinter as tkinter
    
    class c:
    
        def __init__(self):
            r = tkinter.Tk()
            B = tkinter.Button
            B(r,text='quit',command=r.destroy).pack(side=tkinter.BOTTOM)
            B(r,text='GO',command=self).pack(side=tkinter.BOTTOM)
            f = tkinter.Frame(r)
            f.pack(side=tkinter.BOTTOM)
            e = tkinter.Entry(r)
            e.pack(side=tkinter.BOTTOM)
            e.insert(0,'ExAmPlE')
            v = tkinter.IntVar()
            v.set(0)
            R = tkinter.Radiobutton
            R(f,text='lower',variable=v,value=0,font=("Helvetica","12")).pack(
                side=tkinter.LEFT)
            R(f,text='UPPER',variable=v,value=1,font=("Helvetica","16")).pack(
                side=tkinter.LEFT)
            self.root = r
            self.radio = v
            self.entry = e
            r.mainloop()
    
        def __call__(self):
            e = self.entry
            value = e.get()
            e.delete(0,tkinter.END)
            e.insert(0,(string.lower,string.upper,)[self.radio.get()](value))
    
    if '__main__' == __name__:
        c()
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo