1 #转换为大写字母 2 from tkinter import * 3 def convertToUpperCase(event): 4 conOfentName.set(conOfentName.get().upper()) 5 6 window = Tk() 7 window.title("学习") 8 conOfentName = StringVar() #定义一个变量 9 entName = Entry(window,textvariable=conOfentName) 10 entName.grid(padx=100,pady=150) 11 entName.bind("<Button-3>",convertToUpperCase)#右击鼠标 12 window.mainloop() 13 14 15 #只读输入控件 16 from tkinter import * 17 def convertToUpperCase(event): 18 conOfentName.set(conOfentName.get().upper()) 19 20 window = Tk() 21 window.title("学习") 22 conOfentName = StringVar() #定义一个变量 23 entName = Entry(window,width=20,state="readonly") 24 entName.grid(padx=100,pady=150) 25 window.mainloop() 26 27 # 28 from tkinter import * 29 window = Tk() 30 window.title("学习") 31 conOfentName = StringVar() #定义一个变量 32 entName = Entry(window,state="readonly",textvariable=conOfentName) 33 entName.grid(padx=100,pady=150) 34 conOfentName.set("Hello world") 35 window.mainloop() 36 37 38 #列表控件 39 from tkinter import * 40 L=[1,2,3,4,5,6] 41 window = Tk() 42 window.title("学习") 43 conOfentName = StringVar() #定义一个变量 44 entName = Listbox(window,width=100,height=15,listvariable=conOfentName) 45 entName.grid(padx=100,pady=150) 46 conOfentName.set(tuple(L)) 47 window.mainloop() 48 49 #颜色列表 50 from tkinter import * 51 def changeBGC(event): 52 lstColors["bg"] = lstColors.get(lstColors.curselection()) 53 window = Tk() 54 window.title("学习") 55 L=["red","blue","yellow","orange"] 56 conOflstColors = StringVar() #定义一个变量 57 lstColors = Listbox(window,width=100,height=15,listvariable=conOflstColors) 58 lstColors.grid(padx=100,pady=150) 59 conOflstColors.set(tuple(L)) 60 lstColors.bind("<<ListboxSelect>>",changeBGC) 61 window.mainloop() 62 63 #颜色列表排序 64 from tkinter import * 65 def sortItems(event): 66 L.sort() 67 conOflstColors.set(tuple(L)) 68 69 window = Tk() 70 window.title("学习") 71 L=["red","blue","yellow","orange"] 72 conOflstColors = StringVar() #定义一个变量 73 lstColors = Listbox(window,width=100,height=15,listvariable=conOflstColors) 74 lstColors.grid(padx=100,pady=150) 75 conOflstColors.set(tuple(L)) 76 lstColors.bind("<Button-3>",sortItems) #右键鼠标 77 window.mainloop()