Python Forum
Trying to access a method from my Toplevel Form
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to access a method from my Toplevel Form
#1
I'm new to Python programming so please bare with me. I have a tkinter app in which I have a Toplevel Form (a MDI form in the .Net world) that contains a Menu widget. I also have several Child forms which are bound to menu options. At this point everything is defined in the single .py file. I'm not using any user defined classes so far. All my widgets are defined in a method called "create_vendor_form(self()". The below code is where I'm getting hung up at. The error message I'm getting is on the line with the red print. The compTxt widge is defined in the "create_vendor_form()" method. I'm not sure what I'm doing wrong. This seems like pretty straight-forward code.

        # This snipped is from the "create_vendor_form()" method[attachment=3331]
		frame.add_btn = tk.Button(frame, text="Add Record", width=15)
		frame.add_btn.place(x=80, y=205)
		frame.add_btn.bind("<Button-1>", add_vendor)
Thanks,
Blake

Attached Files

Thumbnail(s)
   
Reply
#2
Maybe bind like this:
frame.add_btn.bind("<Button-1>", self.add_vendor)
This will pass an event argument to the add_vendor method. You must either add an event arg to that method, or use a partial or lambda expression to remove the argument. This shows using a lambda.
frame.add_btn.bind("<Button-1>", lambda event: self.add_vendor())
If you have an error, please post the error message and the entire error trace.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pass a variable between tkinter and toplevel windows janeik 9 9,008 Oct-05-2023, 04:22 AM
Last Post: janeik
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 4,532 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Toplevel window menator01 5 7,904 Apr-18-2022, 06:01 PM
Last Post: menator01
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 6,355 Jan-07-2022, 10:10 PM
Last Post: finndude
  [Tkinter] Images in Toplevel() finndude 4 6,616 Mar-09-2021, 09:39 AM
Last Post: finndude
  Create image on a Toplevel using tkinter ViktorWong 3 11,169 Jun-13-2020, 03:21 PM
Last Post: deanhystad
  [Tkinter] Connect Toplevel Radiobuttons to root Label/Entry widgets iconit 2 4,374 Apr-28-2020, 06:50 AM
Last Post: iconit
  [Tkinter] how can disable menu [About] when Toplevel is active balenaucigasa 0 3,944 Oct-25-2019, 09:49 PM
Last Post: balenaucigasa
  [Tkinter] Toplevel window and global widgets? KevinBrown 3 7,252 Apr-25-2019, 06:02 PM
Last Post: Yoriz
  [Tkinter] Notebook accessing a specific tab using a button from a toplevel frame honestie 8 24,621 Sep-12-2018, 01:51 AM
Last Post: honestie

Forum Jump:

User Panel Messages

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