混沌代码求助
  • 板块学术版
  • 楼主wangzc2012
  • 当前回复10
  • 已保存回复11
  • 发布时间2024/2/28 21:05
  • 上次更新2024/2/28 22:51:10
查看原帖
混沌代码求助
1221613
wangzc2012楼主2024/2/28 21:05

事件背景

有一天,小王(本蒟蒻)想要借他爸爸的?(手机),但他的爸爸没有同意,于是小王写下了这一段混沌代码,希望能要到他爸爸的?,但由于代码非常混乱,代码中出现了亿些小问题,小王希望有神犇能帮忙调一下代码

代码BUG

  • xt和disagree函数中6.png和7.png无法显示
  • eee函数中的win窗口如果去掉,2.png和3.png件无法显示

混沌代码

import tkinter as tk
from tkinter import messagebox
import random
import os
import time

z=0
qui=0
tong=0
root=tk.Tk()
root.configure(background='white')


# 这个函数不做任何事,实际上让关闭按钮失效(win)
def callback():
    pass 

x = int((root.winfo_screenwidth() - 560) / 2)
y = int((root.winfo_screenheight() - 465) / 2)
xxx = int(root.winfo_screenwidth())
yyy = int(root.winfo_screenheight())


def xt(event):#当鼠标悬停在不同意按钮上
    global root
    global z
    global photo
    global tong

    buttonl.place_forget()
    buttonl.place(x=random.randint(0, 1800), y=random.randint(0, 1015))
    if tong>=1:
        labell=tk.Label(root,text="      不能反悔哦     o(*^@^*)o                           ",font=("微软雅黑",35))
        labell.place(x=600,y=600)
    else:
        labell=tk.Label(root,text="      同意一下嘛     o(*^@^*)o                           ",font=("微软雅黑",35))
        labell.place(x=600,y=600)
    buttonl.place_forget()
    buttonl.place(x=random.randint(0, 1800), y=random.randint(0, 1015))
    global z
    z=z+1
    if z>=5:
        def q(event):
            global root
            root.quit()
        canvas=tk.Canvas(root,width=1920,height=1080)
        canvas.place(x=0,y=0)
        messagebox.showerror(title="Windwos提示",message="窗口已崩溃")
        root.config(cursor="none")
        root.bind("<F1>", q)
        photo = tk.PhotoImage(file="6.png")
        tk.Label(root, image=photo).place(x=-2,y=-2)  
        time.sleep(1.5)
        photo = tk.PhotoImage(file="7.png")
        tk.Label(root, image=photo).place(x=-2,y=-2)  
        time.sleep(2)
        messagebox.showerror(title="Windwos提示",message="您的电脑正在被攻击")


#定义函数
def ex():  #如果想关闭窗口
    messagebox.showwarning(title='提示',message='此路不通')
    
def disagree():  #按下不同意按钮
    global root
    global photo
    global tong
    if tong>=1:
        labell=tk.Label(root,text="      不能反悔哦     o(*^@^*)o                           ",font=("微软雅黑",35))
        labell.place(x=600,y=600)
    else:
        labell=tk.Label(root,text="      同意一下嘛     o(*^@^*)o                           ",font=("微软雅黑",35))
        labell.place(x=600,y=600)
    buttonl.place_forget()
    buttonl.place(x=random.randint(0, 1800), y=random.randint(0, 1015))
    global z
    z=z+1
    if z>=5:
        def q(event):
            global root
            root.quit()
        canvas=tk.Canvas(root,width=1920,height=1080)
        canvas.place(x=0,y=0)
        messagebox.showerror(title="Windwos提示",message="窗口已崩溃")
        root.config(cursor="none")
        root.bind("<F1>", q)
        photo = tk.PhotoImage(file="6.png")
        tk.Label(root, image=photo).place(x=-2,y=-2)  
        time.sleep(1.5)
        photo = tk.PhotoImage(file="7.png")
        tk.Label(root, image=photo).place(x=-2,y=-2)  
        time.sleep(2)
        messagebox.showerror(title="Windwos提示",message="您的电脑正在被攻击")
        
def eee():  #按下同意按钮
    global tong
    global root
    global button

    tong+=1

    def qu():
        root.quit()

    if tong==1:#防止退出按钮、文本、图片重复多次出现
        button = tk.Button(text = "退出", font=("微软雅黑",26),command = qu)
        button.pack()
        photo = tk.PhotoImage(file="3.png")#图片
        tk.Label(root, image=photo).place(x=982,y=90)
        phot = tk.PhotoImage(file="2.png")#图片
        tk.Label(root, image=phot).place(x=516,y=90)
        labell=tk.Label(root,text="我就知道你会同意的,嘻嘻 (๑•ᴗ•๑)♡               ",font=("微软雅黑",35))
        labell.place(x=600,y=600)

    messagebox.showinfo(title='提示',message='双击“退出”即可退出')
    
    
    photo = tk.PhotoImage(file="3.png")#图片
    tk.Label(root, image=photo).place(x=982,y=90)
    phot = tk.PhotoImage(file="2.png")#图片
    tk.Label(root, image=phot).place(x=516,y=90)


    win = tk.Tk()
    win.protocol('WM_DELETE_WINDOW',callback)
    screen_width = win.winfo_screenwidth()
    screen_height = win.winfo_screenheight()

    win.config(cursor="none")
    win.attributes("-fullscreen",True)
    win.overrideredirect(True)

    #os.system('taskkill /f /im explorer.exe') #关闭任务栏
    win.attributes("-toolwindow", True)

    def GetWindowPos():
        global X,Y
        X = win.winfo_geometry().split("+")[1]
        Y = win.winfo_geometry().split("+")[2]
        win.bind_all('<Configure>', HoldOn)
    def HoldOn(event):
        win.geometry("+{}+{}".format(X,Y))
    win.after(100,GetWindowPos)

    win.resizable(width=False, height=False)
    #win.attributes("-topmost",1)
    win.mainloop()


#结束任务管理器进程
os.system("taskkill /F /IM taskmgr.exe")

#放置画布
canvas=tk.Canvas(root,width=1920,height=1080)
canvas.place(x=0,y=0)

#图片
photo = tk.PhotoImage(file="1.png")
tk.Label(root, image=photo).place(x=795.5,y=150)

#文字
labell=tk.Label(root,text="可以把手机借我看一会儿吗?٩( 'ω' )و 蟹蟹!         ",font=("微软雅黑",35))
labell.place(x=600,y=600)

# 只有通过这个退出按钮才可以退出程序
but1=tk.Button(root,text="同意",font=("微软雅黑",32),command=eee) 
#but1.pack(pady=10)
but1.place(x=787,y=800)
buttonl=tk.Button(root,text="不同意",font=("微软雅黑",32),command=disagree)
buttonl.place(x=1023,y=800)

buttonl.bind("<Enter>", xt)#鼠标悬停在不同意按钮上

#大小不可调整
root.resizable(width=False, height=False)

root.title("小要求")#标题
root.lift()
root.attributes("-topmost",-1) #置于顶层
#root.protocol('WM_DELETE_WINDOW',callback) # 窗体的通信协议方法
root.protocol('WM_DELETE_WINDOW',ex)

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

#不可拖动
def GetWindowPos():
    global X,Y
    X = root.winfo_geometry().split("+")[1]
    Y = root.winfo_geometry().split("+")[2]
    root.bind_all('<Configure>', HoldOn)
def HoldOn(event):
    root.geometry("+{}+{}".format(X,Y))
#root.geometry("560x465+{}+{}".format(x,y))
root.attributes("-fullscreen",True)
root.overrideredirect(True)
root.after(100,GetWindowPos)


root.attributes("-toolwindow", True)
#os.system('taskkill /f /im explorer.exe') #关闭任务栏


#显示窗口
root.mainloop()

注:1.png为『求你了』表情包

2.png、3.png为『谢谢』表情包

6.png为熊猫烧香图片

7.png为蓝屏图片

希望各位神犇门能帮我调一下代码,当然,如果可以的话,麻烦附上完整代码,谢谢!

2024/2/28 21:05
加载中...