Button in python tkinter 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: how to create a button python
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 3: add button python
from tkinter import *
master = Tk()
def closewindow():
exit()
button = Button(master, text="close window", command=closewindow)
button.pack()
mainloop()