Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Tkinter, problem assosiate function to radiobutton

$
0
0
Hi, I'm quite new to python. Trying to write little utility to convert numbers from bin to dec and hexa,and vice versa.
I.m stack onradio buttons selection so far. Any ideas guys, how to "ask" def calc to get variables?
below is my code I've done so far:
import sys
from tkinter import *
from tkinter import messagebox
#my functions will go here...

def sel():#will create label to confirm selection on radio button
    mselection = int(var.get())
    mlabel8 = Label(mGui, text = mselection).grid(row=4, column =1, sticky=W)
    return

        
        
def calc():#main function
    mselection = int(var.get())
    if 'mselection'==1():
        mtext = ment.get()
        mlabel5 = Label(mGui, text=mtext).grid(row=5, column =1, sticky=W)
        return
    elif 'mselection'==2():
        mtext = ment.get()
        mlabel6 = Label(mGui, text=mtext).grid(row=6, column = 1, sticky = W)
        return
    elif 'mselection'==3():
        mtext = ment.get()
        mlabel7 = Label(mGui, text=mtext).grid(row=7, column =1, sticky=W)
        return
        
        
      
        
# my code to add widgets will go here...

mGui=Tk()
mGui.geometry('400x300+600+300')
mGui.title('Binar - Calculator')
ment=IntVar()
var=IntVar()


mlabel1 = Label(mGui,text="Enter your input:"). grid(row=0, column=0, sticky=E)
mEntry1 = Entry(mGui,textvariable = ment).grid(row=0, column=1, sticky=W)
r1 = Radiobutton(mGui, text="1)My input is binary",variable=var,value =1, command=sel).grid(row=1, sticky=W)
r2 = Radiobutton(mGui, text="2)My input is decimal",variable=var,value =2, command=sel).grid(row=2, sticky=W)
r3 = Radiobutton(mGui, text="3)My input is hexadecimal",variable=var,value =3, command=sel).grid(row=3, sticky=W)
mLabel9 = Label(mGui,text="Your selection is: ").grid(row=4, column=0, sticky=E)

mlabel2 = Label(mGui,text="Binary number is:").grid(row=5, column=0, sticky=E)
mlabel3 = Label(mGui,text="Decimal number is:").grid(row=6, column =0, sticky=E)
mlabel4 = Label(mGui,text="Hexadecimal number is:").grid(row=7, column =0, sticky=E)
mButton1 = Button(mGui,text="Calculate", command = calc,).grid(row=8, column=1, sticky =E)




mGui.mainloop()


I'm getting error message like:
>>>
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1442, in __call__
return self.func(*args)
File "C:\Python33\binar1.py", line 15, in calc
if 'mselection'==1():
TypeError: 'int' object is not callable
>>>

Viewing all articles
Browse latest Browse all 51036

Trending Articles