Python Forum
Problem passing argument to functionin inTkinter frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem passing argument to functionin inTkinter frame
#1
This is the method I have inside a Tkinter frame which I am trying to call using key_press() but get the error.


ERROR MESSAGE
Error:
Traceback (most recent call last): File "/home/eric/Python_Projects/Window1.py", line 53, in <module> key_press() TypeError: key_press() takes exactly 1 argument (0 given)
I am struggling to find out which argument to pass.
I am probably making a rookie error here but cannot see the wood from the trees so need some help please.

The function runs ok in IDLE without the call.
CODE SNIPPET

main_window =Tk()

def key_press(event):
   
    if event.keysym == "1":   #if key pressed = 1 then go to next frame
        print ("Next")
    elif event.keysym == "9": # if key pressed = 9 then quit application.
        print ("Quit")
       
    main_window.bind("<Keys>", key_press)

key_press() #call key_press function


main_window.mainloop()
buran write Sep-11-2023, 12:27 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Problem passing argument to functionin inTkinter frame - by ericwm7248 - Sep-11-2023, 12:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug [PyQt] PyQt5 _translate not passing argument Lahearle 2 956 Jul-23-2023, 11:05 AM
Last Post: Axel_Erfurt
  Syntax Error: Positional argument follows keyword argument Rama02 3 4,241 Feb-09-2021, 06:10 PM
Last Post: deanhystad
  Problem passing parameters between windows kenwatts275 2 1,799 Apr-12-2020, 02:43 PM
Last Post: kenwatts275
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 9,223 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 11,445 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 6,673 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020