用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - python代码库

Quick Click

2022-03-13 作者: 云--小荷举报

[python]代码库

from tkinter import *
import random
import tkinter.messagebox
import tkinter as tk

hp = Tk()

hp.title("Quick Click")

hp.geometry("250x150")

hp.iconbitmap("点击.ico")

def 开始():
    global hp
    hp.destroy()#结束开始界面进程
    
    import random
    import tkinter.messagebox
    import tkinter as tk
    import time

    yx = Tk()

    yx.title("Quick Click")

    yx.iconbitmap("点击.ico")

    yx.geometry("386x304")

    global 时间
    时间 = 61#设置全局变量"时间"

    global 得分
    得分 = 0 #设置全局变量"得分"
    
    def 开始():
        global 时间
        global 得分
        var1.set(得分)
        clock = 计时区.after(1000,开始)
        时间 = 时间 - 1
        if 时间 == 0:
            游戏结束 = tk.messagebox.askyesno("","游戏结束")
            最终得分 = tk.messagebox.askyesno("最终得分",  得分)
            yx.destroy()
            pass
        else:
            计时区["state"] = "disabled"
            计时区["text"] = str(时间)
        
    def 小点击():
        global 得分
        小按钮1.place(x = random.randint(10,350),y = random.randint(30,250))
        小按钮2.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮1.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮2.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮3.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮4.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮5.place(x = random.randint(10,350),y = random.randint(30,250))
        警告按钮.place(x = random.randint(10,350),y = random.randint(30,250))
        得分 = int(得分 + 2)
        var1.set(得分)
        yx.update()
        #随机重置按钮位置

    def 普通点击():
        global 得分
        小按钮1.place(x = random.randint(10,350),y = random.randint(30,250))
        小按钮2.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮1.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮2.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮3.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮4.place(x = random.randint(10,350),y = random.randint(30,250))
        普通按钮5.place(x = random.randint(10,350),y = random.randint(30,250))
        警告按钮.place(x = random.randint(10,350),y = random.randint(30,250))
        得分 = int(得分 + 1)
        var1.set(得分)
        yx.update()
        #随机重置按钮位置

    def 警告点击():
        失败 = tk.messagebox.askyesno("","你输了")
        最终得分 = tk.messagebox.askyesno("最终得分",  得分)
        yx.destroy()
        #游戏结束

    def 奖励():
        global 得分
        得分 = int(得分 + 1)
        var1.set(得分)
        yx.update()

    def 帮助():
        帮助1 = tk.messagebox.askyesno("提示","点击各方块有各种特殊情况")
        帮助2 = tk.messagebox.askyesno("提示","白色: 普通方块")
        帮助3 = tk.messagebox.askyesno("提示","绿色: 小方块,加分双倍")
        帮助4 = tk.messagebox.askyesno("提示","红色: 点击后游戏结束")
        #帮助
        

    var1 = tk.StringVar()
    
    标签 = Label(yx,text = "得分",width = 5,height = 1,bg = "white")#得分标签
    得分区 = Label(yx,bg = "white",textvariable = var1,bd = 2)#得分记录
    计时标签 = Label(yx,text = "时间",bg = "white",width = 5,height = 1)#计时标签
    计时区 = Button(yx,bg = "white")#计时记录
    游戏框架 = Canvas(yx,bg = "black",bd = 2)#游戏区域
    小按钮1 = Button(yx,bg = "green",bd = 2,command = 小点击)#小按钮1
    小按钮2 = Button(yx,bg = "green",bd = 2,command = 小点击)#小按钮2
    普通按钮1 = Button(yx,bg = "white",bd = 2,command = 普通点击)#普通按钮1
    普通按钮2 = Button(yx,bg = "white",bd = 2,command = 普通点击)#普通按钮2
    普通按钮3 = Button(yx,bg = "white",bd = 2,command = 普通点击)#普通按钮3
    普通按钮4 = Button(yx,bg = "white",bd = 2,command = 普通点击)#普通按钮4
    普通按钮5 = Button(yx,bg = "white",bd = 2,command = 普通点击)#普通按钮5
    警告按钮 = Button(yx,bg = "red",bd = 2,command = 警告点击)#警告按钮
    奖励按钮 = Button(yx,bg = "gold",bd = 2,command = 奖励)#奖励按钮

    主菜单 = Menu(yx)
    菜单栏 = Menu(yx,tearoff = False)
    菜单栏.add_command(label = "帮助",command = 帮助)
    菜单栏.add_separator()
    菜单栏.add_command(label = "退出",command = yx.destroy)
    主菜单.add_cascade(label = "菜单",menu = 菜单栏)

    yx.config(menu = 主菜单)#菜单设置

    游戏框架.create_rectangle(10,10,110,110)
    游戏框架.place(x = 0,y = 30)#游戏框架

    开始()#开始计时

    标签.place(x = 3,y = 0)
    得分区.place(x = 48,y = 0,width = 50,height = 22)
    计时标签.place(x = 110,y = 0)
    计时区.place(x = 156,y = -1,width = 50,height = 24)
    小按钮1.place(x = random.randint(10,350),y = random.randint(30,250),width = 10,height = 10)
    小按钮2.place(x = random.randint(10,350),y = random.randint(30,250),width = 10,height = 10)
    普通按钮1.place(x = random.randint(10,350),y = random.randint(30,250),width = 30,height = 30)
    普通按钮2.place(x = random.randint(10,350),y = random.randint(30,250),width = 30,height = 30)
    普通按钮3.place(x = random.randint(10,350),y = random.randint(30,250),width = 30,height = 30)
    普通按钮4.place(x = random.randint(10,350),y = random.randint(30,250),width = 30,height = 30)
    普通按钮5.place(x = random.randint(10,350),y = random.randint(30,250),width = 30,height = 30)
    警告按钮.place(x = random.randint(10,350),y = random.randint(30,250),width = 30,height = 30)
    奖励按钮.place(x = 600,y = 500,width = 30,height = 30)
    
    yx.mainloop()

    #游戏界面

def 关于():
    关于 = tk.messagebox.askyesno("关于","作者: 云-小荷")   

开始 = Button(hp,text = "点击开始游戏",width = 10,height = 1,font = ("Arial",11),command = 开始)

开始菜单 = Menu(hp)

开始菜单.add_command(label = "关于",command = 关于)

hp.config(menu = 开始菜单)

开始.place(x = 72,y = 40)

hp.mainloop()

#开始界面

[源代码打包下载]




网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...