1from tkinter import *
2#Creating a win
3win = Tk()
4#Giving a Function To The Button
5def btn1():
6 print("I Don't Know Your Name")
7#Creating The Button
8button1 = Button(win, text="Click Me To Print SomeThing", command=btn1)
9#put on screen
10button1.pack()
11win.mainloop()
12#NB:This programme Will Print Something In The Terminal
13#Check My Profile To See How We Print On The Screen Or Type In Google "Tkinter Label"
1import tkinter as tk #We will use tkinter
2
3font = 'Helvetica' #This is the font that we will use
4
5def cmd(): #This is the command for our button
6 label = tk.Label(master,text="Hi to everyone",font=(font,16)) #We'll create
7 #a label
8 label.grid(row=1,column=0,sticky='w') #This is the 'grid'
9
10class main: #Our main class
11 def __init__(self,master):
12 master.title('Simple Interface') #The title of our interface
13 master.geometry('500x500+0+0') #Position and Size of master
14 button = tk.Button(master,text='Ok',command=cmd) #Creating the button
15 button.grid(row=0,column=0,sticky='w') #Grid of the button
16
17if __name__ == '__main__':
18 master = tk.Tk() #Now we're creating the window
19 main = main(master)
20 master.mainloop #Mainloop of master (the window)
1from tkinter import *
2
3wow = Tk()
4
5def ree(hi):
6 print(hi)
7
8w = Button ( master=wow, command=ree('hi'), text="hi" )
9
10Output:
11 Tkinter:
12 ______
13 [ hi ] <--- Button
14 ------
15
16 Shell:
17 hi <--- on button pressed
1from tkinter import *
2
3
4master = Tk()
5
6#program you want the button to execute
7def closewindow():
8 exit()
9
10#set up button
11button = Button(master, text="close window", command=closewindow)
12
13button.pack()
14
15mainloop()
16
1import Tkinter
2import tkMessageBox
3
4top = Tkinter.Tk()
5
6def helloCallBack():
7 tkMessageBox.showinfo( "Hello Python", "Hello World")
8
9B = Tkinter.Button(top, text ="Hello", command = helloCallBack)
10
11B.pack()
12top.mainloop()