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()
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)
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()
4.定时器
self.timer = QTimer(self) # 初始化一个定时器self.timer.setInterval(1000) # 定时器间隔时间self.timer.start() # 设置计时间隔并启动self.timer.timeout.connect(self.onTimerOut) #每隔一秒执行一次onTimerOut方法
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()
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";}
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)