Entry(root, text='input your text here').pack()
e = StringVar()
entry = Entry(root, textvariable=e).pack()
e.set('input your text here')
e2 = StringVar()
entry = Entry(root, textvariable=e2)
e2.set('not modify')
entry.pack()
entry['state'] = 'readonly'
widget = Radiobutton( master, parameter=value, ... )
widget = Button( master, parameter=value, ... )
import tkinter
# create a window
root = tkinter.Tk()
# Create a framework
frame = tkinter.Frame(root)
root.mainloop()
import tkinter
# create a window
root = tkinter.Tk()
# Create a framework
frame = tkinter.Frame(root)
# Place the frame
frame.pack(padx= 20,pady = 10)
# Create variables
v1 = tkinter.StringVar()
v2 = tkinter.StringVar()
v3 = tkinter.StringVar()
# Create a label
L1 = tkinter.Label(frame,text = ' Simple calculator ',font = ' Microsoft YaHei ,30')
L2 = tkinter.Label(frame,text = '=')
# Place labels
L1.grid(row = 0,column = 2,pady = 10,padx = 10)
L2.grid(row = 1,column = 2,padx= 10,pady = 10)
# Define the filtering method
def text(content):
return content.isdigit()
# Create an input window
e1 = tkinter.Entry(frame,width = 10,textvariable = v1,validate = 'key',validatecommand = (text,'%P'))
e2 = tkinter.Entry(frame,width = 10,textvariable = v2,validate = 'key',validatecommand = (text,'%P'))
e3 = tkinter.Entry(frame,width = 10,textvariable = v3,validate = 'key',validatecommand = (text,'%P'),state ='readonly')
# Placement input
e1.grid(row = 1,column = 0,pady =10,padx = 10)
e2.grid(row = 1,column = 1,padx = 10,pady = 10)
e3.grid(row = 1,column = 3,padx = 10,pady = 10)
# Define the calculation method
def add():
result = int(v1.get()) + int(v2.get())
v3.set(result)
def subtract():
result = int(v1.get()) - int(v2.get())
v3.set(result)
def ride():
result = int(v1.get()) * int(v2.get())
v3.set(result)
def division():
result = int(v1.get()) / int(v2.get())
v3.set(result)
# Create keys
b0 = tkinter.Button(frame,text = '+',command = add,bd = 5)
b1 = tkinter.Button(frame,text = '-',command = subtract,bd = 5)
b2 = tkinter.Button(frame,text = '*',command = ride,bd = 5)
b3 = tkinter.Button(frame,text = '/',command = division,bd = 5)
# Place the keys
b0.grid(row = 2,column = 0,padx = 10,pady = 10)
b1.grid(row = 2,column = 1,pady = 10)
b2.grid(row = 2,column = 2,pady = 10)
b3.grid(row = 2,column = 3,pady = 10)
# Enter the message loop
root.mainloop()
tkinter Control
Python Tkinter Grid Layout manager details