前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >我的tkinter学习笔记6

我的tkinter学习笔记6

作者头像
用户6367961
发布2020-04-15 18:32:00
3600
发布2020-04-15 18:32:00
举报
文章被收录于专栏:自学测试之道

这篇文章继续学习下文字滚动显示

1、文字滚动显示

截图是静态的,动态的请尝试运行代码

代码语言:javascript
复制
from tkinter import *
import time
root = Tk()
root.title("文字滚动效果")
root.geometry("320x240+100+100")
show_str = StringVar(root)
show_str.set("this")
source_str = "欢迎关注公众号<自学测试之道>,一起体验测试的味道!"
stopflag = True
pos = 0
def marquee(widget):
   textwidth = 20
   strlen = len(source_str)
   global pos
   if strlen - pos < 20:
       show_str.set(source_str[pos:pos+textwidth] + source_str[0:20 - strlen + pos])
   else:
       show_str.set(source_str[pos:pos+textwidth])
   pos += 1
   if pos > strlen:
       pos = 0
   global stopflag
   if stopflag:
       widget.after(300, marquee, widget)

show_lb = Label(root, textvariable=show_str, bg='red', compound='center')
show_lb.place(x=20, y=20, width=200, height=30)

def startmarque():
   global stopflag
   stopflag = True
   marquee(show_lb)

def stopmarquee():
   global stopflag
   stopflag = False

button1 = Button(root, text="开始", command=startmarque)
button2 = Button(root, text="停止", command=stopmarquee)
button1.place(x=20, y=100, width=50, height=30)
button2.place(x=200, y=100, width=50, height=30)
root.mainloop()

2、获取系统当前实时时间

代码语言:javascript
复制
import time
import tkinter as tk

class App:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("获取系统时间")
        self.label = tk.Label(text="")
        self.label.pack()
        self.update_clock()
        self.root.mainloop()

    def update_clock(self):
        now = time.strftime("%Y-%m-%d %H:%M:%S")
        self.label.configure(text = now)
        self.root.after(1000,self.update_clock)

app = App()

3、其他实时数据显示

https://blog.csdn.net/u013468614/article/details/58689735

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-04-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 自学测试之道 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档