pyqt小计
发布日期:2021-08-16 20:25:33 浏览次数:3 分类:技术文章

本文共 2029 字,大约阅读时间需要 6 分钟。

1.定时器

1 import threading 2  3 #定义函数 4  5 def fun_timer(): 6     print('hello timer')   #打印输出 7     global timer  #定义变量 8     timer = threading.Timer(1,fun_timer)   #60秒调用一次函数 9     # #定时器构造函数主要有2个参数,第一个参数为时间,第二个参数为函数名10     timer.start()    #启用定时器11 timer = threading.Timer(1,fun_timer)  #首次启动12 timer.start()
View Code

2.图片转为py文件

import base64def pic_to_py(path_):    """    将图像文件转换为py文件    :param path_:    :return:    """    with open(path_, "rb") as f:        read_pic = f.read()    b64str = base64.b64encode(read_pic)    write_data = "img = " + '"' + b64str.decode("utf-8") + '"'    print(write_data)    write_path = path_.replace('.', '_') + ".py"    with open(write_path, "w+") as f:        f.write(write_data)if __name__ == '__main__':    path = "timg.png"  # 要转成py文件的图片名字    pic_to_py(path)
View Code

3.将py文件生成图片

import base64from app_png import img as app_pngbs4 = base64.b64decode(app_png)print(type(bs4))tmp = open('new_app.png', 'wb+')tmp.write(bs4)tmp.close()
View Code

4.定时器

self.timer = QTimer(self)  # 初始化一个定时器self.timer.setInterval(1000)  # 定时器间隔时间self.timer.start()  # 设置计时间隔并启动self.timer.timeout.connect(self.onTimerOut)  #每隔一秒执行一次onTimerOut方法
View Code

5.TextEdit文字滚动

self.gundong_text.textChanged.connect(self.textchanged)  #文字以改变就执行textchanged方法def textchanged(self):    self.gundong_text.moveCursor(QTextCursor.End) #移动光标位置#隐藏光标和滚动条self.textEdit.setReadOnly(True)self.textEdit.verticalScrollBar().hide()
View Code

6.加载外部qss文件

1 1.新建qss文件 2  3 QTabWidget#tabWidget:pane {
4 border-width: 0; 5 background: #ffffff; 6 } 7 QTabBar:tab { 8 border-image: url(:/tab-normal.png); 9 width: 90px;10 height: 35px;11 color: #999999;12 font: 12px "Microsoft Yahei";}
View Code
2.读取外部qss def readQssFile(self, filePath):        with open(filePath, 'r', encoding='utf-8') as fileObj:            styleSheet = fileObj.read()        return styleSheet3.指定控件设置setStyleSheetstyleSheet = self.readQssFile('./test.qss')self.tabWidget.setStyleSheet(styleSheet)
View Code

 

转载于:https://www.cnblogs.com/gaoyukun/p/10423611.html

转载地址:https://blog.csdn.net/weixin_30823001/article/details/95774805 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:题解 P2801 【教主的魔法】
下一篇:012_Eclipse中使用 HDFS URL API 事例介绍

发表评论

最新留言

不错!
[***.144.177.141]2024年03月22日 20时25分48秒