今天的主题
tkinter应用,参考运行结果效果图
上代码 import tkinter import tkinter.messagebox import tkinter.ttk listboxStudents=[] root=tkinter.Tk() root.title('老衲的tkinter 出发啦~') root['height']=400 root['width']=320 lableName=tkinter.Label(root,text='肥肥名字:',justify=tkinter.RIGHT,width=70) lableName.place(x=10,y=5,width=70,height=20) varName=tkinter.StringVar(value='') entryName=tkinter.Entry(root,width=120,textvariable=varName) entryName.place(x=70,y=5,width=50,height=20) lableGrade=tkinter.Label(root,text='肥肥尺寸:',justify=tkinter.RIGHT,width=70) lableGrade.place(x=10,y=40,width=70,height=20) studentClasses={ '大肥肥':['大肥肥','中肥肥','小肥肥','肥肥全家桶'], '中肥肥':['中小肥肥','中中肥肥'], '小':['小大肥肥','小中肥肥','小小肥肥'] } comboGrade=tkinter.ttk.Combobox(root,values=tuple(studentClasses.keys()),width=70) comboGrade.place(x=70,y=40,width=50,height=20) def comboChange(event): grade=comboGrade.get() if grade: comboClass["values"]=studentClasses.get(grade) else: comboClass.set([ ]) comboGrade.bind('<<ComboboxSelected>>',comboChange) lableClass=tkinter.Label(root,text='肥肥型号:',justify=tkinter.RIGHT,width=70) lableClass.place(x=130,y=40,width=70,height=20) comboClass=tkinter.ttk.Combobox(root,width=50) comboClass.place(x=190,y=40,width=50,height=20) lableSex=tkinter.Label(root,text='肥肥性别:',justify=tkinter.RIGHT,width=70) lableSex.place(x=10,y=70,width=70,height=20) sex=tkinter.IntVar(value=1) radioMan=tkinter.Radiobutton(root,variable=sex,value=1,text='Man') radioMan.place(x=70,y=70,width=70,height=20) radioWoman=tkinter.Radiobutton(root,variable=sex,value=0,text='Woman') radioWoman.place(x=130,y=70,width=70,height=20) monitor=tkinter.IntVar(value=0) checkMonitor=tkinter.Checkbutton(root,text='肥猩猩的选择',variable=monitor,onvalue=1,offvalue=0) checkMonitor.place(x=20,y=100,width=100,height=20) def addInformation(): result='Name:'+entryName.get() result=result+';大肥肥:'+comboGrade.get() result=result+';中肥肥:'+comboClass.get() result=result+';肥肥性别:'+('男' if sex.get() else '女') result=result+';添加啊,选择啊:'+('yes' if monitor.get() else 'No') listboxStudents.insert(0,result) buttonAdd=tkinter.Button(root,text='选择',width=40,command=addInformation()) buttonAdd.place(x=130,y=100,width=40,height=20) def deleteSeclection(): selection=listboxStudents.curselection() if not selection: tkinter.messagebox.showinfo(title='还是确定',message='No Seclection') else: listboxStudents.delete(selection) buttonDelete=tkinter.Button(root,text='确定啊',width=100,command=deleteSeclection) buttonDelete.place(x=180,y=100,width=100,height=20) listboxStudents=tkinter.Listbox(root,width=300) listboxStudents.place(x=10,y=130,width=300,height=200) root.mainloop()
平时自己研究的,还用不上研究深入
代码就懒得写了 直接参考了https://blog.csdn.net/m0_37639542/article/details/70159856