Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:23:15+00:00 2026-06-04T21:23:15+00:00

I’m planning on having quite a lot of methods for my program so I

  • 0

I’m planning on having quite a lot of methods for my program so I need to implement these in external files and add it to menu commands after importing the file. But since menu commands takes only names of the methods, I’m not sure whether it can work if my method takes parameters. Below is the code for displaying an image in a file named file.py:

from tkinter import *
from tkinter.filedialog import askopenfilename
from PIL import Image, ImageTk

def open(root):
    filename = askopenfilename(filetypes=[("all files","*"),("Bitmap Files","*.bmp; *.dib"),
                                        ("JPEG", "*.jpg; *.jpe; *.jpeg; *.jfif"),
                                        ("PNG", "*.png"), ("TIFF", "*.tiff; *.tif")])
    image = Image.open(filename)
    image1 = ImageTk.PhotoImage(open(filename))
    root.geometry("%dx%d+%d+%d" % (image.size[0], image.size[1], 0, 0))
    panel = Label(root, image = image1)
    panel.pack(side='top', fill='both', expand='yes')
    panel.image = image1

I also have a file named gui.py, where I call the method open above in a command. So I did this:

menu.add_command(label="Open", command=file.open)

My idea is to display the image in the same window as the menu, so I guess the method open need to take the parameter root so when it is called in the menu, the image will be opened in that window. I’m not sure if it’s logic but here is the error that I got:

Exception in Tkinter callback Traceback (most recent call last):
File "D:\Python32\lib\tkinter_init_.py", line 1399, in call
return self.func(*args) TypeError: open() takes exactly 1 argument (0 given)

I’m new to Python and my question is a little bit messy but I really need help. Thanks.

Regarding the comment about binding, even though I’m not sure how to fix it, but when I add the parameter to the open method called as menu command, it works except that the method is called instead of being assigned to the command. How can I call the name of the method only but still include the parameter? This is bizarre for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:23:16+00:00Added an answer on June 4, 2026 at 9:23 pm

    Thanks for the comment about binding, even though I’m not sure how to fix it, but when I add the parameter to the open method called as menu command, it works except that the method is called instead of being assigned to the command.

    Instead of using

    menu.add_command(label="Open", myfunc(myarg))
    

    use

    menu.add_command(label="Open", lambda: myfunc(myarg))
    

    This adds the argument, but waits to run the function until add_command decides to call it.

    More about lambda

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
Thanks in advance for your help. I have a need within an application to
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.