Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created April 5, 2024 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigilantPotato/08b54535babdf92388ed7b5fa85c62d6 to your computer and use it in GitHub Desktop.
Save vigilantPotato/08b54535babdf92388ed7b5fa85c62d6 to your computer and use it in GitHub Desktop.
How to use button widget (pass argument)
import ctypes
import tkinter
from tkinter import ttk
def clicked(widget):
print(widget["text"] + " is clicked!")
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
b1 = tkinter.Button(root, text="Button", bg="lightblue", width=15, command=lambda:clicked(b1))
b2 = tkinter.Button(root, text="Button_color", width=15, bg="black", fg="white", command=lambda:clicked(b2))
b3 = tkinter.Button(root, text="relief", width=15, bg="cyan", relief="solid", command=lambda:clicked(b3))
b4 = ttk.Button(root, text="ttk_Button", width=15, command=lambda:clicked(b4))
b1.pack(pady=1), b2.pack(pady=1), b3.pack(pady=1), b4.pack(pady=1)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment