pyqt小计

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 base64


def 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 base64
from app_png import img as app_png

bs4 = 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 styleSheet

3.指定控件设置setStyleSheet
styleSheet = self.readQssFile('./test.qss')
self.tabWidget.setStyleSheet(styleSheet)
View Code

 

posted @ 2019-02-23 18:00  MISF  阅读(200)  评论(0编辑  收藏  举报
     JS过度和变形效果演示   
  
    html5.png