-1

As the title says, my create_button function doesn't give an error when using a command as a lambda function and another as "comm".

Here is a code snippet to make the question more clear:

        self.create_button("pi", 8, 1, comm=self.pi)
        self.create_button("e", 8, 2, comm=self.euler)
        self.create_button("His.", 8, 3, comm=self.history)
        

    #functie care creaza butoanele
    def create_button(self, text, row, column, comm=None):
        button = tk.Button(self.button_frame, text=text, width=4, height=1, font=self.display_font, activebackground='Gold', command=lambda: self.button_click(text), comm=comm)
        button.grid(row=row, column=column, padx=5, pady=5)

Why does "comm=comm" work in calling a function? For example, if I change "comm" with "cmd", upon running the file I will get the next error: _tkinter.TclError: unknown option "-cmd".

So does anyone have any idea why it works?

1 Answers1

0

Tkinter lets you use any unique abbreviation for any option, so comm is just shorthand for command - cmd doesn't' work because it's not an abbreviation of command.

A button can only use the command option once. It's a quirk that it lets you specify it twice under two different names, but it still only uses the value from one.

If you need to call two functions, the best solution is to create a third command which calls the two functions. The button can this call this new function.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thank you! That's what I thought about at first but when I searched up the documentation I didn't find anything about abbreviations or anything about this quirk. My use of the abbreviation was coincidental and it surprised me that it worked. – JustAConfusedGuy May 12 '23 at 15:08