Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Arguments in function for button command
#1
New to Python. No matter what I enter, it doesn't like the arguments in the function. Appreciate any help.
Error:
Exception in Tkinter callback Traceback (most recent call last):   File "C:\Python27\lib\lib-tk\Tkinter.py", line 1536, in __call__     return self.func(*args) TypeError: go() takes exactly 1 argument (0 given)
The function is inside a class and the command for a button. It takes entries from two entry boxes and a spinbox. The time part works fine separately, and it does get the spinbox info ok.   
def go(self):
        def time():
            e1= entry1.get()
            e2= entry2.get()
            run_time_min= float(e1)
            run_time_sec= float(e2)
            time= run_time_min * 60 + run_time_sec
            return time
        
        def calc():
            sb1 = spinbox1.get()
            if sb1 == '8mm':
                feet=time/fpsecs8
                print feet
            elif sb1 == 'Super 8':
                feet= time/fpsecss8
                print feet
            elif sb1 == '16mm':
                feet= time/fpsecs16
                print feet
            elif sb1 == '16 Sound':
                feet= time/fpsecs16s
                print feet
Quote
#2
You aren't showing enough code.
Where is your class definition, and the code that calls it ?
Your passing args, but the functions that you are showing don't receive any
Quote
#3
Sorry. Here's more.
class FilmCalc(Frame):
 
   def __init__(self, parent):
       Frame.__init__(self, parent)    
       self.parent = parent
       self.initUI()
       
   def initUI(self):
       self.parent.title("Film Calculator")
       self.grid

       frame1 = Frame(root)
       frame1.grid

   frame_rate_8=float(17)
   frame_rate_s8 = float(17)
   frame_rate_16 = float(20)
   frame_rate_16s = float(24)
   fpft8 = float(80)
   fpfts8 = float(72)
   fpft16 = float(40)
   fpsecs8 = fpft8/frame_rate_8
   fpsecss8 = fpfts8/frame_rate_s8
   fpsecs16 = fpft16/frame_rate_16
   fpsecs16s = fpft16/frame_rate_16s
   global spinbox1
   global entry1
   global entry2
   entry1 = IntVar(None)
   entry2 = IntVar(None)
   global time
   
   def go(self):
       def time():
           e1= entry1.get()
           e2= entry2.get()
           run_time_min= float(e1)
           run_time_sec= float(e2)
           time= run_time_min * 60 + run_time_sec
           return time
       
       def calc():
           sb1 = spinbox1.get()
           if sb1 == '8mm':
               feet=time/fpsecs8
               print feet
           elif sb1 == 'Super 8':
               feet= time/fpsecss8
               print feet
           elif sb1 == '16mm':
               feet= time/fpsecs16
               print feet
           elif sb1 == '16 Sound':
               feet= time/fpsecs16s
               print feet

   def reset():
           entry1.delete(0, END)
           entry2.delete(0, END)
           spinbox1.selection_clear()

   spinbox1 = Spinbox(root, values= ("8mm", "Super 8", "16mm", "16 Sound"), wrap = TRUE)
   spinbox1.grid(row=0, column=1, padx=105, pady=15)
   
   lbl1 = Label(root, text="Minutes", width=8)
   lbl1.grid(row=2, column=2, pady=15, sticky=W)           
  
   entry1 = Entry(root, justify= RIGHT)
   entry1.grid(row=2, column=1, pady=15)
   
   lbl2 = Label(root, text="Seconds", width=8)
   lbl2.grid(row=3, column=2, sticky=W)        

   entry2 = Entry(root, justify= RIGHT)
   entry2.grid(row=3, column=1)
   
   resetButton = Button(root, text="Reset", command= reset)
   resetButton.grid(row=4, column=1, pady=100)
   
   calcButton = Button(root, text="Calculate", command= go)
   calcButton.grid(row=4, column=2)
Edit admin:
Use code tag,look BBcode help.
Quote
#4
Did you import tkinter like
from tkinter import *
Quote
#5
Yes. It makes the window and fields correctly, but fails when pressing the calculate button.


from Tkinter import *

root = Tk()
root.geometry("450x350+200+100")

class FilmCalc(Frame):
  
    def __init__(self, parent):
        Frame.__init__(self, parent)    
        self.parent = parent
        self.initUI()
        
    def initUI(self):
        self.parent.title("Film Calculator")
        self.grid

        frame1 = Frame(root)
        frame1.grid

    frame_rate_8=float(17)
    frame_rate_s8 = float(17)
    frame_rate_16 = float(20)
    frame_rate_16s = float(24)
    fpft8 = float(80)
    fpfts8 = float(72)
    fpft16 = float(40)
    fpsecs8 = fpft8/frame_rate_8
    fpsecss8 = fpfts8/frame_rate_s8
    fpsecs16 = fpft16/frame_rate_16
    fpsecs16s = fpft16/frame_rate_16s
    global spinbox1
    global entry1
    global entry2
    entry1 = IntVar(None)
    entry2 = IntVar(None)
    global time
    
    def go(self):
        def time():
            e1= entry1.get()
            e2= entry2.get()
            run_time_min= float(e1)
            run_time_sec= float(e2)
            time= run_time_min * 60 + run_time_sec
            return time
        
        def calc():
            sb1 = spinbox1.get()
            if sb1 == '8mm':
                feet=time/fpsecs8
                print feet
            elif sb1 == 'Super 8':
                feet= time/fpsecss8
                print feet
            elif sb1 == '16mm':
                feet= time/fpsecs16
                print feet
            elif sb1 == '16 Sound':
                feet= time/fpsecs16s
                print feet

    def reset():
            entry1.delete(0, END)
            entry2.delete(0, END)
            spinbox1.selection_clear()

    spinbox1 = Spinbox(root, values= ("8mm", "Super 8", "16mm", "16 Sound"), wrap = TRUE)
    spinbox1.grid(row=0, column=1, padx=105, pady=15)
    
    lbl1 = Label(root, text="Minutes", width=8)
    lbl1.grid(row=2, column=2, pady=15, sticky=W)           
   
    entry1 = Entry(root, justify= RIGHT)
    entry1.grid(row=2, column=1, pady=15)
    
    lbl2 = Label(root, text="Seconds", width=8)
    lbl2.grid(row=3, column=2, sticky=W)        

    entry2 = Entry(root, justify= RIGHT)
    entry2.grid(row=3, column=1)
    
    resetButton = Button(root, text="Reset", command= reset)
    resetButton.grid(row=4, column=1, pady=100)
    
    calcButton = Button(root, text="Calculate", command= go)
    calcButton.grid(row=4, column=2) 
    
    #lbl3 = Label(root, text= entry1.cget())
    #lbl3.grid(row=5, column=1, pady= 100)
  
app = FilmCalc(root)
root.mainloop()
Quote
#6
There is no 'go' command
Quote
#7
It's the command for the calcButton.
Quote
#8
Didn't find it first time

you need
def go(self, event):
Quote
#9
Error:
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1536, in __call__
    return self.func(*args)
TypeError: go() takes exactly 2 arguments (0 given)


I had tried that before, and it still gives the above error.
Quote
#10
also need
command=self.go
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [WxPython] Help with passing arguments into a wx.Panel ? merlem 7 223 Jan-26-2017, 02:09 PM
Last Post: merlem
  [Tkinter] Make A Button That Opens Another Tk() Window That I Have Made Saif133 5 227 Jan-20-2017, 08:10 PM
Last Post: scriptso
  [Tkinter] I have a Toplevel button in tkinker that I want to close the window and then perform Bloodypizza17 2 147 Jan-06-2017, 07:18 PM
Last Post: Bloodypizza17

Forum Jump:


Users browsing this thread: 1 Guest(s)