Python| GUI界面进行学生与作业匹配

应人之邀,写一个学生和作业进行随机匹配并通过GUI窗口显示的程序。

from tkinter import *
import random
import tkinter.font as tkFont
import csv

def start():

    fun()


# 学生名字长度要与作业长度匹配
names = ['','',''
        ]

homework = ['b311',
            'D068',
            'D069',
            'D070',
            'D071',
            'D072',
            'D073',
            'D074',
            'D075',
            'D076',
            'D077',
            'D078',
            'D079',
            'D080',
            'D081',
            'D082',
            'D083',
            'D084',
            'D085',
            'D086',
            'D087',
            'D088',
            'D089',
            'D090',
            'D091',
            'D092',
            'D093',
            'D094',
            'D095',
            'D096',
            'D097',
            'D098',
            'D099',
            'D100',
            'D101',
            'D102',
            'D103',
            'D104',
            'D105',
            'D106',
            'D107',
            'D108',
                    ]

result = []

def fun():
    
    student  = names[random.randint(0, len(names)-1)]
    work = homework[random.randint(0, len(homework)-1)]
    names.remove(student)
    homework.remove(work)
    result.append([student, work])
    with open('作业匹配.csv','w+', newline='') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerows(result)
    root.update()  #不断更新
    root.after(1) 
    Label(root, text= student+'   '+work , font = ("华文宋体",60),fg = "red" , width = 18,height = 2).place(x = 300,y = 500,anchor = 'nw') 
    
root = Tk()

myfont = tkFont.Font(family='华文宋体', size=50, weight=tkFont.BOLD, slant=tkFont.ITALIC, underline=0, overstrike=0)
myfont1 = tkFont.Font(family='华文宋体', size=50, weight=tkFont.BOLD, slant=tkFont.ITALIC, underline=0, overstrike=0)

root.geometry('1400x900',) # 窗口大小

lb1 = Label(root, text='作业匹配', font=myfont,)
lb1.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.1)


btn1 = Button(root, text='开始作业匹配', command=start,font=myfont, bg = "orange")
btn1.place(relx=0.3, rely=0.4, relwidth=0.4, relheight=0.1)


# btn2 = Button(root, text='结束', command=stop,font=myfont, bg = "gray")
# btn2.place(relx=0.55, rely=0.4, relwidth=0.3, relheight=0.1)


root.mainloop()



效果图如下
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiao黄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值