tkinter button widget code example
Example 1: Function to a button in tkinter
from tkinter import *
win = Tk()
def btn1():
print("I Don't Know Your Name")
button1 = Button(win, text="Click Me To Print SomeThing", command=btn1)
button1.pack()
win.mainloop()
Example 2: python button tkinter
from tkinter import *
wow = Tk()
def ree(hi):
print(hi)
w = Button ( master=wow, command=ree('hi'), text="hi" )
Output:
Tkinter:
______
[ hi ] <--- Button
------
Shell:
hi <--- on button pressed
Example 3: button tkinter
import Tkinter
import tkMessageBox
top = Tkinter.Tk()
def helloCallBack():
tkMessageBox.showinfo( "Hello Python", "Hello World")
B = Tkinter.Button(top, text ="Hello", command = helloCallBack)
B.pack()
top.mainloop()
Example 4: add a button on tkinter
import tkinter
button1 = ttk.Button(self, text="anything", command=random command)
button1.pack()
Example 5: add button python
from tkinter import *
master = Tk()
def closewindow():
exit()
button = Button(master, text="close window", command=closewindow)
button.pack()
mainloop()