最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

氣輕PyQt6 14 單選按鈕(QRadioButton), 按鈕組

2023-03-13 08:01 作者:氣輕  | 我要投稿

?

增加了六個單選按鈕,形成了一個按鈕組。點擊單選按鈕后,選擇的結果會顯示在標簽控件。

?

from PyQt6.QtWidgets import *

from PyQt6.QtGui import QFont, QIcon, QPixmap

from PyQt6.QtCore import Qt, QDate, pyqtSignal

import sys

import datetime

import numpy as np

?

timeLabel = ['早飯前', '早飯后', '午飯前', '午飯后', '晚飯前', '晚飯后']

?

class PyQt614(QWidget):

??? def __init__(self):

??????? super().__init__()

??????? self.initUI()

??? def initUI(self):

??????? self.setWindowTitle('氣輕PyQt6')??????????????? # 設置窗口標題

??????? self.resize(420, 120)?????????????????????????? # 設置窗口大小

?

??????? dateData = datetime.datetime.now().date()

??????? dateLabel = dateData.strftime('%Y-%m-%d')

??????? self.edit = QLineEdit(self)???????????????????? # 輸入框

??????? self.edit.setGeometry(10, 0,230, 40)??????????? # 設置位置和大小

??????? self.edit.setReadOnly(True)???????????????????? # 只讀

??????? self.edit.setText(dateLabel)

??????? self.edit.setAlignment(Qt.AlignmentFlag.AlignHCenter)# 居中設置

??????? self.edit.setStyleSheet('background-color:#FFE4B5;color : #32CD32; \

??????????????????? font: bold italic large /"Times New Roman/";font-size:25px')

?

??????? self.btn = QPushButton('', self)

??????? self.btn.setGeometry(250,0,40,40)??????????? ???# 設置位置和大小

??????? self.btn.setIcon(QIcon(QPixmap('Date.png')))

??????? self.btn.clicked.connect(self.calendarOn)

?

??????? self.stage = QLabel(self)?????????????????????? #設置label信息

??????? self.stage.setGeometry(290, 0,120, 40)????????? # 設置位置和大小

????? ??self.stage.setText(timeLabel[0])

??????? self.stage.setObjectName('label')

??????? self.stage.setToolTip('時段')?????????????????? # 設置label提示

??????? self.stage.setAlignment(Qt.AlignmentFlag.AlignHCenter)# 居中設置

??????? self.stage.setStyleSheet('background-color:yellow;color : #6495ED; \

??????????????????? font: bold italic large /"Times New Roman/";font-size:25px')

?

??????? self.rg = QButtonGroup(self)

???????

??????? rdict = dict.fromkeys(timeLabel)

??????? x, y=np.meshgrid([80, 180, 280], [60, 80])

??????? xdict = dict(zip(timeLabel, x.ravel()))

??????? ydict = dict(zip(timeLabel, y.ravel()))

?

?

??????? for i, s in enumerate(timeLabel):

??????????? rdict[s] = QRadioButton(self)

??????????? rdict[s].setText(s)

??????????? rdict[s].move(xdict[s], ydict[s])

??????????? self.rg.addButton(rdict[s],i)

??????? rdict[timeLabel[0]].setChecked(True)??????? # 設置第一個單選框被選中

??????? self.rg.buttonClicked.connect(self.updateStage)

?

??????? self.show()

?

??? def updateEdit(self,t):

??????? self.edit.setText(t)

?

??? def calendarOn( self ):

??????? self.calWin = CalendarWin(self.edit)

??????? self.calWin.show()

??????? self.calWin.move(900,700)

??????? self.calWin.signal.connect(self.updateEdit)??? # 連接信號與槽

?

??? def updateStage(self,val):

??????? self.stage.setText(timeLabel[self.rg.checkedId()])

?

class CalendarWin(QWidget):

??? signal = pyqtSignal( str )????????????????????????? #定義一個信號

??? def __init__(self,t):

??????? super().__init__()

??????? self.t = t

??????? self.setWindowTitle('日期')

??????? self.resize(440, 220)

??????? cal = QCalendarWidget(self)

??????? cal.setGridVisible(True)

??????? cal.resize(400,160)

??????? cal.move(10,10)

??????? cal.clicked[QDate].connect(self.emitDate)??? # 按下按鈕時發(fā)送信號

?

??? def emitDate(self,date):

??????? self.signal.emit(date.toString("yyyy-MM-dd"))

??????? self.close()

?

if __name__ == '__main__':

??? app = QApplication(sys.argv)

??? window = PyQt614()

??? sys.exit(app.exec())

?

執(zhí)行結果


氣輕PyQt6 14 單選按鈕(QRadioButton), 按鈕組的評論 (共 條)

分享到微博請遵守國家法律
宁夏| 湖北省| 张家界市| 恩平市| 肥乡县| 安国市| 凉城县| 贵阳市| 那曲县| 城市| 巴楚县| 阿拉善左旗| 中牟县| 扎鲁特旗| 南城县| 南川市| 开化县| 胶南市| 封开县| 秦安县| 榕江县| 贵州省| 霍林郭勒市| 泗阳县| 贵德县| 平顺县| 萝北县| 射洪县| 赤城县| 化州市| 昌邑市| 永定县| 六安市| 三河市| 云和县| 额济纳旗| 常山县| 龙川县| 衡山县| 合阳县| 迁安市|