利用tkinter制作一个用户界面(正式版)
哈咯大家好,最近呢。。。。很忙 所以这个文章就鸽了很久
话不多说直接上代码!!
YZM.py
验证码代码如下:
import random
from PIL import Image, ImageFont, ImageDraw, ImageFilter
def rnd_tuple1():
a = random.randint(0,127)
b = random.randint(0,127)
c = random.randint(0,127)
return(a,b,c)
def rnd_tuple2():
a = random.randint(127,255)
b = random.randint(127,255)
c = random.randint(127,255)
return (a, b, c)
def rnd_char():
return chr(random.randint(97,122))
def YZM():
image = Image.new("RGB",(240,60),(0,255,0))
draw = ImageDraw.Draw(image)
for x in range(240):
for y in range(60):
draw.point((x,y),rnd_tuple1())
font = ImageFont.truetype("arial.ttf",36)
chr = ""
for t in range(4):
c = rnd_char()
chr += c
draw.text((60*t+10,10),c,rnd_tuple2(),font)
image.save("dwa.png")
return chr
login.py
主程序代码:
import tkinter as tk
import tkinter.messagebox
import webbrowser
import time
import os
import YZM
window = tk.Tk()
window.title("请登录以使用Windows家庭中文版:")
window.geometry("700x700")
#验证输入
yan2 = tk.StringVar()
e = tk.Entry(window, show = None,textvariable = yan2)
e.pack()
#username输入
log2 = tk.StringVar()
logbox = tk.Entry(window,show = None, textvariable = log2)
logbox.pack()
#密码输入
pwd2 = tk.StringVar()
pwdbox = tk.Entry(window, show = "密", textvariable = pwd2)
pwdbox.pack()
canvas = tk.Canvas(window, width = 300, height = 300)
image_file = tk.PhotoImage(file = "dwa.png")
yan = ""
def yzm():
global yan
yan = YZM.YZM()
image_file.config(file = "dwa.png")
t = tk.messagebox.askyesno(title = "已刷新验证码", message = "已刷新验证码,如果您没眼瞎可以看到(必选(是))")
if not t:
webbrowser.open("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=249787579,3804609413&fm=26&gp=0.jpg")
tk.messagebox.showwarning(title = "请立即退出Windows!!", message = "您眼瞎了,请立即关机电脑!!!")
return yan
image = canvas.create_image(200,40,anchor = "n", image = image_file)
canvas.pack(side = "top")
yanzhengma_shurukaung = tk.Label(window,text = "验证码:" )
yanzhengma_shurukaung.place(x=180, y=0)
login_inputbox = tk.Label(window, text = "用户名:")
login_inputbox.place(x = 180, y = 25)
pwd_inputbox = tk.Label(window, text = "密码:")
pwd_inputbox.place(x = 180, y = 45)
tk.Label(window, text = "通过右侧图片以输入验证码>>").place(x = 100, y = 120)
tk.Label(window, text = "该操作版本系统仅GUI界面制作人晓得...", font = ("微软雅黑",26)).place(x = 60, y = 200)
log_user ="xxxxxx"
log_pwd = "12345"
def rxtc():
buyao = tk.messagebox.askyesno(title = "", message = "确定要残忍退出吗??qwq")
if buyao:
azhe = tk.messagebox.askyesno(title = "...", message = "嘿嘿,你真以为退出有那么简单吗")
if azhe:
lj1 = tk.messagebox.askyesno(title = "...", message = "嘿嘿,你真以为退出有那么简单吗")
if lj1:
lj2 = tk.messagebox.askyesno(title="...", message="嘿嘿,你真以为退出有那么简单吗")
if lj2:
lj3 = tk.messagebox.askyesno(title = "...", message = "嘿嘿,你真以为退出有那么简单吗")
if lj3:
window.quit()
def kanmima():
tk.messagebox.showinfo(title = "密码来啦", message = " 账户名:119796946184\n 密码:itellu\n 用了会有大惊喜[狗头]")
def realmima():
tk.messagebox.showinfo(title = "密码在这嘞", message = " 账户名:xxxxxx\n 密码:12345\n 别告诉其他人[狗头]")
def hit_me():
check = yan2.get()
check2 = log2.get()
check3 = pwd2.get()
if check == yan and check2 == log_user and check3 == log_pwd:
tk.Label(window, text = '登录中', ).place(x = 50, y = 300)
canvas = tk.Canvas(window, width = 465, height = 22, bg = "white")
canvas.place(x = 110, y = 300)
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width = 0, fill = "green")
x = 500
n = 465 / x
for i in range(x):
n = n + 465 / x
canvas.coords(fill_line, (0, 0, n, 60))
window.update()
time.sleep(0.00001)
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width = 0, fill = "white")
tk.messagebox.askyesno(title = "Windows提示", message="登录成功,是否进入该操作系统?")
window.destroy()
os.system("slidetoshutdown")
else:
tk.Label(window, text = '检测到匿名用户,正在开启战斗模块,请勿关闭', ).place(x = 250, y = 325)
canvas = tk.Canvas(window, width = 465, height = 22, bg = "white")
canvas.place(x = 110, y = 300)
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width = 0, fill = "red")
x = 500
n = 465 / x
for i in range(x):
n = n + 465 / x
canvas.coords(fill_line, (0, 0, n, 60))
window.update()
time.sleep(0.001)
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width = 0, fill = "white")
while 1:
webbrowser.open("ihasabucket.com")
tk.messagebox.showerror(title = "输入有误 危险!!电脑处于危机状态!!", message = "错误,错误!!系统被匿名_067347不明用户劫持......")
menubar = tk.Menu(window)
filemenu = tk.Menu(menubar, tearoff = 0)
menubar.add_cascade(label = ">点这退出<", menu = filemenu)
filemenu.add_command(label = ">退出1<", command = rxtc)
filemenu.add_command(label = ">退出2<", command = rxtc)
filemenu.add_command(label = ">退出3<", command = rxtc)
submenu = tk.Menu(filemenu, tearoff = 0)
filemenu.add_cascade(label = "退出?>>", menu = submenu)
submenu.add_command(label = "退出??^_^", command = rxtc)
submenu.add_command(label = "退出??>_<", command = rxtc)
submenu.add_command(label = "退出??>.<", command = rxtc)
filemenu.add_separator()
filemenu.add_command(label = "退出", command = rxtc)
def zuozhe():
tk.messagebox.showinfo(title="作者", message= "本程序由Python开发者Shane_hcker精心制作")
def accredit():
tk.messagebox.showinfo(title = "版权信息.Copyright", message = "随意转载啦,反正后果自负啦!")
about = tk.Menu(menubar, tearoff = 1)
menubar.add_cascade(label= "关于", menu = about)
about.add_command(label = "作者", command = zuozhe)
about.add_command(label = "版权", command = accredit)
realpwd = tk.Menu(menubar, tearoff = 1)
menubar.add_cascade(label = "<别点我,我这密码是假的>", menu = realpwd)
realpwd.add_command(label = "点这查看密码", command = realmima)
window.config(menu = menubar)
pawdmenu = tk.Menu(menubar, tearoff = 1)
menubar.add_cascade(label = "嘿嘿,密码在这!", menu = pawdmenu)
pawdmenu.add_command(label = "点这查看密码【滑稽】", command = kanmima)
tk.Button(window, text = "刷新", width = 15, height = 2, command = yzm).place(x = 550, y = 120)
r = tk.Button(window, text = "登录", width = 15, height = 2, command = hit_me)
r.pack()
window.mainloop()