前言:继上次写的背单词小程序之后,最近又学了Tkinter库的应用,编写了一个简易的选课小程序 哈~哈
import tkinter as tk course=['Pyhon','Java','Linux','计算机网络','编译原理','单片机','形势与政策','ACM'] window=tk.Tk() window.title("zw选课程序") window.geometry('600x600') l=tk.Label(window,text="欢迎来到选课程序",bg='green',width=30,height=3) l.grid(row=0,column=1) window.geometry('600x600') theRB=tk.Listbox(window) theLB=tk.Listbox(window) for item in course: theLB.insert(0,item) theLB.grid(row=1,column=0,rowspan=4) ############################################## def callbutton1(): for i in theLB.curselection(): theRB.insert(0,theLB.get(i)) theLB.delete(i) def callbutton2(): for i in theRB.curselection(): theLB.insert(0,theRB.get(i)) theRB.delete(i) def callbutton3(): for i in range(0,theLB.size()): theRB.insert(0,theLB.get(i)) for i in range(theLB.size()-1,-1,-1): theLB.delete(i) def callbutton4(): for i in range(0,theRB.size()): theLB.insert(0,theRB.get(i)) for i in range(theRB.size()-1,-1,-1): theRB.delete(i) ############################################################## #--------------选课按钮----------------------------- ############################################################## tb1=tk.Button(window,text='>',command=callbutton1,width=20) tb3=tk.Button(window,text='>>',command=callbutton3,width=20) tb2=tk.Button(window,text='<',command=callbutton2,width=20) tb4=tk.Button(window,text='<<',command=callbutton4,width=20) ############################################################### #操作说明:>:一次选择点击的课程 # >>:选择列表框的全部课程 # <:后悔选择的课程 # <<:后悔选择全部课程 ########################################################## tb1.grid(row=1,column=1) tb2.grid(row=3,column=1) tb3.grid(row=2,column=1) tb4.grid(row=4,column=1) ############################################################## theRB.grid(row=1,column=2,rowspan=4) l1=tk.Label(window,text="18jk2班->AiY",bg='yellow',width=30,height=1) l1.grid(row=5,column=1) window.mainloop()
运行结果: