跳至主要内容

tkinter 练习之大转盘

参考资料
https://www.codermantra.com/tkinter-python-tutorial/


import tkinter
# 导入线程模块
import threading
import time

root = tkinter.Tk()
root.title('转盘抽奖')

#更改左上角图标
root.iconbitmap(r'C:\src\dragon-face.ico')
root.minsize(290,370)


# 摆放按钮
btn1 = tkinter.Button(root, text = '蓝牙耳机', bg = 'red')
btn1.place(x = 20, y = 20, width = 70, height = 70)

btn2 = tkinter.Button(root, text = '再来一次', bg = 'white')
btn2.place(x = 110, y = 20, width = 70, height = 70)

btn3 = tkinter.Button(root, text = '抱枕', bg = 'white')
btn3.place(x = 200, y = 20, width = 70, height = 70)

btn4 = tkinter.Button(root, text = '谢谢惠顾', bg = 'white')
btn4.place(x = 20, y = 110, width = 70, height = 70)

btn5 = tkinter.Button(root, text = '保温杯', bg = 'white')
btn5.place(x = 200, y = 110, width = 70, height = 70)

btn6 = tkinter.Button(root, text = '充电宝', bg = 'white')
btn6.place(x = 20, y = 200, width = 70, height = 70)

btn7 = tkinter.Button(root, text = 'iphoneX', bg = 'white')
btn7.place(x = 110, y = 200, width = 70, height = 70)

btn8 = tkinter.Button(root, text = '谢谢惠顾', bg = 'white')
btn8.place(x = 200, y = 200, width = 70, height = 70)

# 将所有选项组成列表
prizelists = [btn1,btn2,btn3,btn5,btn8,btn7,btn6,btn4]

# 是否开启循环的标志
isloop = False
# 是否运行的标志
functions = False

def round():
    # 判断是否开始循环(防止多次按下开始按钮程序开启多次转盘循环)
    if isloop == True:
        return

    # 初始化计数变量
    i = 0
    while True:
        # 延时操作
        time.sleep(0.06)
        # 将所有组件的背景颜色变为白色
        for j in prizelists:
            j['bg'] = 'white'
        # 将当前数值对应的组件变色
        prizelists[i]['bg'] = 'red'

        i += 1
        # 如果i大于最大索引直接归零
        if i >= len(prizelists):
            i = 0
        if functions == True:
            continue
        else:
            break

# 建立一个新线程的函数
def newtask():
    global isloop
    global functions
    # 建立线程
    t = threading.Thread(target = round)
    # 开启线程运行
    t.start()
    # 设置循环开始标志
    isloop = True
    # 是否运行的标志
    functions = True

# 定义停止循环的函数
def stop():
    global isloop
    global functions

    functions = False
    isloop = False

# 开始按钮
btn_start = tkinter.Button(root, text = '开始', command = newtask)
btn_start.place(x = 80, y = 300, width = 50, height = 50)

# 结束按钮

btn_stop = tkinter.Button(root, text = '结束', command = stop)
btn_stop.place(x = 150, y = 300, width = 50, height = 50)

root.mainloop()

评论

此博客中的热门博文

学习地址

清华大学计算机系课程攻略 https://github.com/PKUanonym/REKCARC-TSC-UHT 浙江大学课程攻略共享计划 https://github.com/QSCTech/zju-icicles https://home.unicode.org/ 世界上的每个人都应该能够在手机和电脑上使用自己的语言。 http://codecanyon.net   初次看到这个网站,小伙伴们表示都惊呆了。原来代码也可以放在网上卖的?!! 很多coder上传了各种代码,每个代码都明码标价。看了下销售排行,有的19刀的卖了3万多份,额di神啊。可以看到代码的演示效果,真的很漂亮。代码以php、wordpress主题、Javascript、css为主,偏前台。 https://www.lintcode.com/ 算法学习网站,上去每天刷两道算法题,走遍天下都不怕。 https://www.codecademy.com/ 包含在线编程练习和课程视频 https://www.reddit.com/ 包含有趣的编程挑战题,即使不会写,也可以查看他人的解决方法。 https://ideone.com/ 在线编译器,可运行,可查看代码示例。 http://it-ebooks.info/ 大型电子图书馆,可即时免费下载书籍。 刷题 https://github.com/jackfrued/Python-100-Days https://github.com/kenwoodjw/python_interview_question 面试问题 https://github.com/kenwoodjw/python_interview_question https://www.journaldev.com/15490/python-interview-questions#python-interpreter HTTP 身份验证 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Authentication RESTful 架构详解 https://www.runoob.com/w3cnote/restful-architecture.html https://www.rosettacode.org/wiki/Rosetta_C...

MechanicalSoup

用于自动与网站交互的 Python 库。 MechanicalSoup 自动存储和发送 cookie,跟踪重定向,并且可以跟踪链接和提交表单。 它不执行 JavaScript。 https://github.com/MechanicalSoup/MechanicalSoup https://mechanicalsoup.readthedocs.io/en/stable/index.html https://realpython.com/python-web-scraping-practical-introduction/ pip show Mechanicalsoup 找到模块的安装位置 https://stackoverflow.com/questions/54352162/download-file-with-mechanicalsoup # Install dependencies # pip install requests # pip install BeautifulSoup4 # pip install MechanicalSoup # Import libraries import mechanicalsoup import urllib.request import requests from bs4 import BeautifulSoup import re # Create a browser object that can collect cookies browser = mechanicalsoup.StatefulBrowser() browser.open("https://www.ons.gov.uk/economy/grossdomesticproductgdp/timeseries/l2kq/qna") browser.download_link(link_text=".xls",file="D:/ONS_Data.xls" )

Chrome浏览器

谷歌搜索 双引号——精确搜索 冒号后加文件类型——搜索特定类型的结果 关键词 后 site:**——搜索特定网站的关键词 +、-关键词——实现特定需求筛选 Google中/——快捷键入浏览·搜索框 关键词后..——搜索特定范围(地点)关键词 intitle:关键词——搜索特定标题 用 puppeteer 直接运行 chrome 爬 https://github.com/puppeteer/puppeteer Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议 控制 Chrome 或 Chromium 。Puppeteer默认 无头 运行,但可以配置为运行完整(非无头)Chrome 或 Chromium。 了解如何为 Chrome 开发扩展程序 https://developer.chrome.com/docs/extensions/mv3/ 什么是Chrome插件 https://github.com/sxei/chrome-plugin-demo Google Workspace 状态信息中心 https://www.google.com/appsstatus#hl=zh&v=status 此页面提供属于“Google Workspace”的服务的状态信息 谷歌浏览器离线下载 https://support.google.com/chrome/answer/95346?co=GENIE.Platform%3DDesktop&hl=zh-Hans 企业版 https://cloud.google.com/chrome-enterprise/browser/download 也可以在谷歌浏览器 帮助中心 中搜索chrome https://www.google.com/intl/zh-CN/chrome/?standalone=1 chrome 打开新网页时不要覆盖 鼠标 中键(滚轮)点击超链接 ,或者右击超链接,选择新标签页打开, 还有点链接的同时按下 Ctrl 键也可以 谷歌在线翻译网页 http://translate.google.com/translate?u= http://www.dropitproject.com/index.php 打开chrome浏览器按 F6 ,等同于按 ...