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()
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
from tkinter import * master = Tk() #program you want the button to execute def closewindow(): exit() #set up button button = Button(master, text="close window", command=closewindow) button.pack() mainloop()