1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | class Demo(QWidget): def __init__( self ): super (Demo, self ).__init__() # 设置标题 icon 尺寸 self .setWindowTitle( "Demo" ) self .setWindowIcon(QtGui.QIcon( './ico/ico.png' )) self .resize( 1090 , 900 ) # 更改绘图的背景颜色 - 'w': 白色 pg.setConfigOption( 'background' , 'w' ) # 更改前端字体类显示颜色 - 'k': 黑色 pg.setConfigOption( 'foreground' , 'k' ) # Button style_setting = "background-color: #d0d0d0; color: #000000 ;padding: 8px ; border-width: 10px ; border-radius: 4px ; border-color: #FAEBD7;" self .button1 = QPushButton( self ) self .button1.setText( 'start' ) self .button1.setStyleSheet(style_setting) self .button1.move( 5 , 10 ) self .button1.clicked.connect( self .start) # ComboBox self .box0 = QtWidgets.QComboBox( self ) self .box0.setGeometry(QtCore.QRect( 15 , 20 , 100 , 30 )) self .box0.setStyleSheet(style_setting) list0 = [ '1' , '2' , '3' ] self .box0.addItems(list0) self .box0.currentIndexChanged[ str ].connect( self .settime) if self .box0.currentText(): self .time = int ( self .box0.currentText()) # Label self .label = QtWidgets.QLabel( self ) self .label.setGeometry(QtCore.QRect( 30 , 30 , 100 , 100 )) self .label.setText( "<font color=red size=32 > <b>hello</b>" ) # PlotWidget self .p1 = PlotWidget( self ) self .p1.setLabel(axis = 'bottom' , text = 'C1' ) self .p1.setGeometry(QtCore.QRect( 15 , 40 , 200 , 100 )) self .p1.setYRange(x, y) self .curve1 = self .p1.plot(np.random.normal(size = 100 ), pen = 'cc0033' ) self .curve1.setData(np.array(data)) # TextEdit self .word = QTextEdit( self ) # self.word.setObjectName("show") self .word.setWindowTitle( "show" ) self .word.setGeometry(QtCore.QRect( 50 , 10 , 100 , 200 )) self .word.setFrameShape(QtWidgets.QFrame.Box) #Box/Panel self .word.setFrameShadow(QtWidgets.QFrame.Raised) #Raised、Sunken、Plain self .word.setLineWidth( 2 ) self .word.setStyleSheet( 'border-width: 1px;border-style: solid;border-color: rgb(0, 0, 0);background-color: rgb(255, 255, 255);' ) # self.word.setWordWrap(True) self .word.setAlignment(Qt.AlignLeft | Qt.AlignTop) # self.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint) # 设置无边框窗口 self .word.setCursor(Qt.IBeamCursor) self .t1 = self .wordlabel.textCursor() #光标 self .t2 = QTextCharFormat() self .t2.setFontFamily( '黑体' ) self .t2.setFontPointSize( 20 ) self .t1.insertText( self .seq, self .t2) self .word.clear() # 清空内容 # Thread self .my_thread = ComThread() self .my_thread.expSignal.connect( self .data) self .my_thread.start() self .my_thread.close_port() class ComThread(QThread): expSignal = pyqtSignal( bool ) def __init__( self ): super (ComThread, self ).__init__() def push( self ): self .expSignal.emit(data) def run( self ): self .push() if __name__ = = '__main__' : app = QApplication(sys.argv) demo = Demo() demo.show() sys.exit(app. exec ()) |
designer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # QPushButton objectname=Btn1 # line # QLabel # QListWidget objectname=showBox1 # QLineEdit objectname=showBox2 class MyApp(QMainWindow, Ui_list[ 0 ][ 0 ]): dataSignal = pyqtSignal( str ) def __init__( self ): QMainWindow.__init__( self ) Ui_list[ 0 ][ 0 ].__init__( self ) self .setupUi( self ) self .Btn1.clicked.connect( lambda : self .Clicked( 0 )) self .dataSignal.connect( self .showdata) def showdata( self ,data): cnt = self .showBox1.count() if cnt > 50 : #最多显示N条信息 self .showBox1.takeItem( 0 ) self .showBox1.addItem(data) def Clicked( self ,n): if n = = 0 : data = self .showBox2.text() self .dataSignal.emit(data) inputs = self .showBox2.setText( 'input' ) if __name__ = = '__main__' : QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) # 防止控件变形 app = QApplication(sys.argv) window = MyApp() window.show() sys.exit(app.exec_()) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现