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

  • SEARCH
  • Home
  • 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 7529337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:38:06+00:00 2026-05-30T04:38:06+00:00

i want to point, that i am learning python since short time. The question

  • 0

i want to point, that i am learning python since short time.
The question is going be to beginner one.

I need to add command to menu at top of program, which would call function “color_picker(“red”).

kolory.add_command(label="Czerwony", command=color_picker('red'))
When i am using that, its somehow wrong, cuz its called once the program started, its not waiting for me to click the menu button. (i am sure of it, as i added “showinfo” to that function, and it shows the message before i do anything)
kolory.add_command(label="Czerwony", command=lambda: color_picker('red')) That one kinda works, but i don’t know what does “lambda” mean here. Is it only way to call functions with arguments under menu options?

Same question goes to binding keyboard shortcuts.
okno.bind("1", color_picker) – that will call the function but does not have the argument, which should be a color. How can i do that?

So, how to assign functions WITH arguments, to keyboard shortcuts and to menu using add_command?

PS. Was searching trough google, but it seems python does not have so good documentation like c# does for example. Or i am too stupid to find it.

EDIT:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
TypeError: color_picker() takes at most 1 argument (2 given)

Thats the error message, when i try to use “pick_red” in okno.bind

  • 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-05-30T04:38:07+00:00Added an answer on May 30, 2026 at 4:38 am

    I’m not sure if I understand the question, but here goes;

    The problem is that you are calling the color_picker function (by adding () after the function name).

    What you want to do is pass the actual function, not the result of the function call as the command keyword argument, e.g. add_command(label="Czerwony", command=color_picker)

    However, since you want to give it a fixed argument 'red', you must use partial from functools, something like;

    from functools import partial
    pick_red = partial(color_picker, "red")
    kolory.add_command(label="Czerwony", command=pick_red)
    

    EDIT:

    Now that your error message shows that you are using Tkinter, we can see that according to documentation the function that is given to bind() is always passed an event parameter, so you need a function that can accept it;

    def pick_red_with_event(event):
        # We really do nothing with event for now but we always get it...
        color_picker("red")
    
    okno.bind("1", pick_red_with_event)
    


    Same thing works for okno.bind, if you have defined pick_red as above, just do:

    okno.bind("1", pick_red)
    

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

Sidebar

Related Questions

I want to try out SICP with Python. Can any one point to materials
I'm learning Python right now and I want to write some script that will
First, in order to provide full disclosure, I want to point out that this
I have this code that I want to make point-free; (\k t -> chr
The problem is that I want to output Mathematica compatible floating point numbers. The
I'm really interested in learning Python for web development. Can anyone point me in
I am currently learning python programming (and am a beginner at it). Currently I
I am learning Python and am making a Q&A script. I made one function
Question: Where is a good starting point for learning to write server applications? Info:
First, I want to point out that this isn't really x86, it's msx88 which

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.