【Tkinter】用Python写一个抽奖系统3.0

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
谨以此文记录学习Tkinter的点点滴滴

目录

登录系统

生日系统

抽奖系统1.0

抽奖系统2.0

抽奖系统3.0

管理员密匙

录入礼物

退出管理员

抽奖系统

完整代码


 

登录系统

生日系统

抽奖系统1.0

抽奖系统2.0

抽奖系统3.0

管理员密匙

        def keys():
            global flag1
            key=var1.get()
            if key==user_keys:
                flag1=1
                var1.set('欢迎管理员进入系统')
            else:
                var1.set('管理员密码错误')

录入礼物

        def gifts():
            global flag1
            if flag1==1:
                gift=var2.get()
                with open('d:\\登录系统\\抽奖3.pickle','rb') as file:
                    lst=pickle.load(file)
                if gift!='录入成功' or gift!='录入失败':
                    lst.append(gift)
                    var2.set('录入成功')
                else:
                    var2.set('录入失败')      
                with open('d:\\登录系统\\抽奖3.pickle','wb') as file:
                    pickle.dump(lst,file)
                    file.close()
            else:
                var2.set('请先输入管理员密码')

退出管理员

        def end():
            global flag1
            flag1=0

抽奖系统

        def choice():
            with open('d:\\登录系统\\抽奖3.pickle','rb') as file:
                lst=pickle.load(file)
            if len(lst)!=0:
                t=r.randint(0,len(lst)-1)
                var3.set(lst[t])
                lst.remove(lst[t])
            else:
                var3.set('ERROR!')
            with open('d:\\登录系统\\抽奖3.pickle','wb') as file:
                pickle.dump(lst,file)
                file.close()

完整代码

#抽奖系统3.0
import tkinter as tk
import turtle as tu
import random as r
import tkinter.messagebox
import pickle
def choujiang():
root_random=tk.Tk()
root_random.title('抽奖系统')
screenheight=root_random.winfo_screenheight()
screenwidth=root_random.winfo_screenwidth()
height=300
width=500
x=(screenwidth-width)//2
y=(screenheight-height)//2
root_random.geometry('%dx%d+%d+%d'%(width,height,x,y))
tk.Label(root_random,text='欢迎光临抽奖系统',font=('宋体',20),bg='white',fg='red',width=20,height=3).place(x=100,y=10)
tk.Label(root_random,text='请选择抽奖方式',font=('宋体',12),fg='black',width=20,height=2).place(x=150,y=100)
def random3():
with open('d:\\登录系统\\抽奖3.pickle','wb') as file:
pickle.dump([],file)
file.close()
global user_keys
user_keys='123456'
random_3=tk.Toplevel(root_random)
random_3.title('新年礼物')
random_3.geometry('%dx%d+%d+%d'%(width,height,x,y))
var1=tk.StringVar()
var2=tk.StringVar()
var3=tk.StringVar()
global flag1
flag1=0
def gifts():
global flag1
if flag1==1:
gift=var2.get()
with open('d:\\登录系统\\抽奖3.pickle','rb') as file:
lst=pickle.load(file)
if gift!='录入成功' or gift!='录入失败':
lst.append(gift)
var2.set('录入成功')
else:
var2.set('录入失败')
with open('d:\\登录系统\\抽奖3.pickle','wb') as file:
pickle.dump(lst,file)
file.close()
else:
var2.set('请先输入管理员密码')
def keys():
global flag1
key=var1.get()
if key==user_keys:
flag1=1
var1.set('欢迎管理员进入系统')
else:
var1.set('管理员密码错误')
def choice():
with open('d:\\登录系统\\抽奖3.pickle','rb') as file:
lst=pickle.load(file)
if len(lst)!=0:
t=r.randint(0,len(lst)-1)
var3.set(lst[t])
lst.remove(lst[t])
else:
var3.set('ERROR!')
with open('d:\\登录系统\\抽奖3.pickle','wb') as file:
pickle.dump(lst,file)
file.close()
def end():
global flag1
flag1=0
tk.Label(random_3,text='新年快乐',font=('宋体',20),width=20,height=2,fg='blue').place(x=110,y=10)
tk.Label(random_3,text='请输入管理员密码',font=('宋体',12),bg='white',fg='black').place(x=60,y=100)
tk.Entry(random_3,textvariable=var1).place(x=220,y=100)
tk.Button(random_3,text='确定',width=5,bg='blue',fg='white',command=keys).place(x=380,y=95)
tk.Label(random_3,text='请录入礼物的信息',font=('宋体',12),bg='white',fg='black').place(x=60,y=150)
tk.Entry(random_3,textvariable=var2).place(x=220,y=150)
tk.Button(random_3,text='录入',width=5,bg='blue',fg='white',command=gifts).place(x=380,y=145)
tk.Button(random_3,text='点击抽奖',width=10,bg='blue',fg='white',command=choice).place(x=210,y=200)
tk.Label(random_3,textvariable=var3,fg='blue',bg='white',font=('宋体',12),width=10,height=2).place(x=208,y=240)
tk.Button(random_3,text='结束',width=5,bg='black',fg='white',command=end).place(x=440,y=145)
random_3.mainloop()
tk.Button(root_random,text='1',fg='black',bg='white',width=5,height=1,command=None).place(x=100,y=150)
tk.Button(root_random,text='2',fg='black',bg='white',width=5,height=1,command=None).place(x=220,y=150)
tk.Button(root_random,text='3',fg='black',bg='white',width=5,height=1,command=random3).place(x=340,y=150)
root_random.mainloop()
choujiang()

 

 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: python