Python Forum
[Tkinter] Button 'command' Argument Confusion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Button 'command' Argument Confusion
#12
Simple example with partial

#! /usr/bin/env python3
import tkinter as tk
from functools import partial

def callback(argument, label):
    label['text'] = f'Called Text -> {argument}'

root = tk.Tk()
root.geometry('250x70+250+250')

label = tk.Label(None)
label['text'] = 'Default text'
label.pack()

btn = tk.Button(None, text = 'Submit')
btn['command'] = partial(callback, 'This text was called', label)
btn.pack()

root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Button 'command' Argument Confusion - by gw1500se - Nov-10-2021, 07:57 PM
RE: Button 'command' Argument Confusion - by Yoriz - Nov-10-2021, 08:27 PM
RE: Button 'command' Argument Confusion - by Yoriz - Nov-11-2021, 06:50 PM
RE: Button 'command' Argument Confusion - by Yoriz - Nov-11-2021, 07:06 PM
RE: Button 'command' Argument Confusion - by Yoriz - Nov-11-2021, 08:14 PM
RE: Button 'command' Argument Confusion - by menator01 - Nov-11-2021, 08:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax Error: Positional argument follows keyword argument Rama02 3 4,325 Feb-09-2021, 06:10 PM
Last Post: deanhystad
  Get name of command button Heyjoe 3 2,482 Dec-10-2020, 04:30 AM
Last Post: deanhystad
  Class function does not create command button Heyjoe 2 2,422 Aug-22-2020, 08:06 PM
Last Post: Heyjoe
  [Tkinter] Command button, then more command buttons Heyjoe 4 3,071 Aug-08-2020, 11:28 AM
Last Post: Yoriz
  [Tkinter] button command tkinter Heyjoe 6 5,724 Jul-30-2020, 07:06 PM
Last Post: deanhystad
  Button Command Heyjoe 4 2,584 Jul-20-2020, 01:45 AM
Last Post: Heyjoe
  tkinter button not accessing the command when clicked jhf2 1 3,797 Nov-23-2019, 10:17 PM
Last Post: DT2000
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,193 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] How to add an argument to a buttons command call petterg 2 3,255 Jun-20-2019, 09:05 PM
Last Post: petterg
  [Tkinter] command button automaticaly fired kferhat 2 2,636 Jun-16-2019, 08:21 PM
Last Post: kferhat

Forum Jump:

User Panel Messages

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