1from tkinter import *
2
3window = Tk()
4# entry box
5my_input = Entry()
6my_input.pack()
7
8window.mainloop()
1import tkinter as tk
2
3def show_entry_fields():
4 print("First Name: %s\nLast Name: %s" % (e1.get(), e2.get()))
5 e1.delete(0, tk.END)
6 e2.delete(0, tk.END)
7
8master = tk.Tk()
9tk.Label(master, text="First Name").grid(row=0)
10tk.Label(master, text="Last Name").grid(row=1)
11
12e1 = tk.Entry(master)
13e2 = tk.Entry(master)
14e1.insert(10, "Miller")
15e2.insert(10, "Jill")
16
17e1.grid(row=0, column=1)
18e2.grid(row=1, column=1)
19
20tk.Button(master,
21 text='Quit',
22 command=master.quit).grid(row=3,
23 column=0,
24 sticky=tk.W,
25 pady=4)
26tk.Button(master, text='Show', command=show_entry_fields).grid(row=3,
27 column=1,
28 sticky=tk.W,
29 pady=4)
30
31master.mainloop()
32
33tk.mainloop()
34
1import tkinter as tk
2
3root= tk.Tk()
4
5canvas1 = tk.Canvas(root, width = 400, height = 300, relief = 'raised')
6canvas1.pack()
7
8label1 = tk.Label(root, text='Calculate the Square Root')
9label1.config(font=('helvetica', 14))
10canvas1.create_window(200, 25, window=label1)
11
12label2 = tk.Label(root, text='Type your Number:')
13label2.config(font=('helvetica', 10))
14canvas1.create_window(200, 100, window=label2)
15
16entry1 = tk.Entry (root)
17canvas1.create_window(200, 140, window=entry1)
18
19def getSquareRoot ():
20
21 x1 = entry1.get()
22
23 label3 = tk.Label(root, text= 'The Square Root of ' + x1 + ' is:',font=('helvetica', 10))
24 canvas1.create_window(200, 210, window=label3)
25
26 label4 = tk.Label(root, text= float(x1)**0.5,font=('helvetica', 10, 'bold'))
27 canvas1.create_window(200, 230, window=label4)
28
29button1 = tk.Button(text='Get the Square Root', command=getSquareRoot, bg='brown', fg='white', font=('helvetica', 9, 'bold'))
30canvas1.create_window(200, 180, window=button1)
31
32root.mainloop()