温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python中Tkinter模块指的是什么

发布时间:2021-05-18 09:31:04 来源:亿速云 阅读:410 作者:小新 栏目:编程语言

这篇文章主要介绍python中Tkinter模块指的是什么,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1、说明

Tkinter模块是Python的标准TkGUI工具包的接口。Tk和Tkinter可以在大多数Unix平台下使用,也可以应用于Windows和Macintosh系统。Tk8.0后续版本可以实现本地窗口风格,在绝大多数平台上运行良好。

2、实例

import tkinter
import time
import threading
from random import random
from tkinter import messagebox as tkMessageBox
 
 
class choujiang:
    # 初始化魔术方法
    def __init__(self):
        # 准备好界面
        self.root = tkinter.Tk()
        self.root.title('lowB版转盘')
        self.root.minsize(300, 300)
        # 声明一个是否按下开始的变量
        self.isloop = False
        self.newloop = False
        self.value = []
        # 调用设置界面的方法
        self.setwindow()
        self.root.mainloop()
 
 
    # 界面布局方法
    def setwindow(self):
        # 开始停止按钮
     self.btn_start = tkinter.Button(self.root, text='start/stop', command=self.newtask)
     self.btn_start.place(x=125, y=125, width=70, height=70)
 
 
     self.btn1 = tkinter.Button(self.root, text='1', bg='red')
     self.btn1.place(x=20, y=20, width=50, height=50)
 
 
     self.btn2 = tkinter.Button(self.root, text='2', bg='white')
     self.btn2.place(x=90, y=20, width=50, height=50)
 
 
     self.btn3 = tkinter.Button(self.root, text='3', bg='white')
     self.btn3.place(x=160, y=20, width=50, height=50)
 
 
     self.btn4 = tkinter.Button(self.root, text='3', bg='white')
     self.btn4.place(x=230, y=20, width=50, height=50)
 
 
     self.btn5 = tkinter.Button(self.root, text='3', bg='white')
     self.btn5.place(x=230, y=90, width=50, height=50)
 
 
     self.btn6 = tkinter.Button(self.root, text='2', bg='white')
     self.btn6.place(x=230, y=160, width=50, height=50)
 
 
     self.btn7 = tkinter.Button(self.root, text='1', bg='white')
     self.btn7.place(x=230, y=230, width=50, height=50)
 
 
     self.btn8 = tkinter.Button(self.root, text='3', bg='white')
     self.btn8.place(x=160, y=230, width=50, height=50)
 
 
     self.btn9 = tkinter.Button(self.root, text='2', bg='white')
     self.btn9.place(x=90, y=230, width=50, height=50)
 
 
     self.btn10 = tkinter.Button(self.root, text='3', bg='white')
     self.btn10.place(x=20, y=230, width=50, height=50)
 
 
     self.btn11 = tkinter.Button(self.root, text='1', bg='white')
     self.btn11.place(x=20, y=160, width=50, height=50)
 
 
     self.btn12 = tkinter.Button(self.root, text='3', bg='white')
     self.btn12.place(x=20, y=90, width=50, height=50)
 
 
      # 将所有选项组成列表
     self.girlfrends = [self.btn1, self.btn2, self.btn3, self.btn4, self.btn5, self.btn6, self.btn7, self.btn8,
                         self.btn9, self.btn10, self.btn11, self.btn12]
 
 
    def rounds(self):
        # 判断是否开始循环
        if self.isloop == True:
            return
        # 初始化计数 变量
        i = 0
        # 死循环
        while True:
            if self.newloop == True:
                self.newloop = False
                self.value = self.girlfrends[i - 1]['text']
                if self.value =='1':
                    tkMessageBox.showinfo( "Winning Result", "恭喜获得一等奖 !'")
                if self.value == '2':
                    tkMessageBox.showinfo("Winning Result", "恭喜获得二等奖 !")
                if self.value == '3':
                    tkMessageBox.showinfo("Winning Result", '恭喜获得三等奖!')
                return
            # 延时操作
            time.sleep(0.1)
            # 将所有的组件背景变为白色
            for x in self.girlfrends:
                x['bg'] = 'white'
            # 将当前数值对应的组件变色
            self.girlfrends[i]['bg'] = 'red'
            # 变量+1
            i += 1
            # 如果i大于最大索引直接归零
            if i >= len(self.girlfrends):
                i = 0
    # 建立一个新线程的函数
    def newtask(self):
        if self.isloop == False:
            # 建立线程
            t = threading.Thread(target=self.rounds)
            # 开启线程运行
            t.start()
            # 设置循环开始标志
            self.isloop = True
        elif self.isloop == True:
            self.isloop = False
            self.newloop = True
#转盘效果
c = choujiang()

python的五大特点是什么

python的五大特点:1.简单易学,开发程序时,专注的是解决问题,而不是搞明白语言本身。2.面向对象,与其他主要的语言如C++和Java相比, Python以一种非常强大又简单的方式实现面向对象编程。3.可移植性,Python程序无需修改就可以在各种平台上运行。4.解释性,Python语言写的程序不需要编译成二进制代码,可以直接从源代码运行程序。5.开源,Python是 FLOSS(自由/开放源码软件)之一。

以上是“python中Tkinter模块指的是什么”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI