<tfoot id='cSWoi'></tfoot>
  • <i id='cSWoi'><tr id='cSWoi'><dt id='cSWoi'><q id='cSWoi'><span id='cSWoi'><b id='cSWoi'><form id='cSWoi'><ins id='cSWoi'></ins><ul id='cSWoi'></ul><sub id='cSWoi'></sub></form><legend id='cSWoi'></legend><bdo id='cSWoi'><pre id='cSWoi'><center id='cSWoi'></center></pre></bdo></b><th id='cSWoi'></th></span></q></dt></tr></i><div id='cSWoi'><tfoot id='cSWoi'></tfoot><dl id='cSWoi'><fieldset id='cSWoi'></fieldset></dl></div>

      • <bdo id='cSWoi'></bdo><ul id='cSWoi'></ul>
    1. <legend id='cSWoi'><style id='cSWoi'><dir id='cSWoi'><q id='cSWoi'></q></dir></style></legend>

        <small id='cSWoi'></small><noframes id='cSWoi'>

        如何使用按钮打开新窗口

        时间:2023-08-04

              <tbody id='refGW'></tbody>
            <legend id='refGW'><style id='refGW'><dir id='refGW'><q id='refGW'></q></dir></style></legend>
                <bdo id='refGW'></bdo><ul id='refGW'></ul>

                • <tfoot id='refGW'></tfoot>

                • <small id='refGW'></small><noframes id='refGW'>

                • <i id='refGW'><tr id='refGW'><dt id='refGW'><q id='refGW'><span id='refGW'><b id='refGW'><form id='refGW'><ins id='refGW'></ins><ul id='refGW'></ul><sub id='refGW'></sub></form><legend id='refGW'></legend><bdo id='refGW'><pre id='refGW'><center id='refGW'></center></pre></bdo></b><th id='refGW'></th></span></q></dt></tr></i><div id='refGW'><tfoot id='refGW'></tfoot><dl id='refGW'><fieldset id='refGW'></fieldset></dl></div>
                  本文介绍了如何使用按钮打开新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何打开一个允许我从以下代码中选择时间的新窗口?我尝试使用connect函数连接到windows2,但似乎出现错误.

                  How do I open a new window which allows me to select the time from the following code? I tried to use connect function to connect to windows2 however it appears that there is an error.

                  我想通过 Dropbox 选择时间,我可以在上午 10 点、上午 11 点等之前选择时间.有谁知道您也可以如何实现这一点?

                  I would like to select time by a dropbox where I could choose time by 10 am, 11 am, ect.. Does anyone know how you could implement this as well?

                  class Window(QMainWindow):
                      def __init__(self):
                          super().__init__()
                  
                          self.label = QLabel()
                          self.calendar = QCalendarWidget()
                          self.title="Select date from calendar"
                          self.left = 600
                          self.top = 300
                          self.width = 500
                          self.height = 480
                          self.iconName = "home.png"
                          self.setWindowTitle(self.title)
                          self.setWindowIcon(QtGui.QIcon(self.iconName))
                          self.setGeometry(self.left, self.top, self.width, self.height)
                  
                          self.proceedbutton = QPushButton("Proceed to select time", self)
                          self.proceedbutton.setGeometry(290, 430, 190, 40)
                          self.proceedbutton.setToolTip("<h3>Start the Session</h3>")
                          self.proceedbutton.clicked.connect(self.window2)
                  
                          self.hide()
                  
                          self.backbutton = QPushButton("Back", self)
                          self.backbutton.setGeometry(200, 430, 80, 40)
                          self.backbutton.setToolTip("<h3>Start the Session</h3>")
                  
                          self.Calendar()
                          self.show()
                  
                      def Calendar(self):
                          CalendarVbox = QVBoxLayout()
                          self.calendar.setGridVisible(True)
                  
                          self.label.setFont(QtGui.QFont("Sanserif", 10))
                          self.label.setStyleSheet('color:black')
                          CalendarVbox.addWidget(self.calendar)
                          CalendarVbox.addWidget(self.label)
                  
                          self.setLayout(CalendarVbox)
                          self.calendar.selectionChanged.connect(self.onSelectionChanged)
                  
                      def window2(self):
                          self.label = QLabel("Select Time", self)
                          self.label.move(200,430)
                          self.setWindowTitle("Select Time")
                          self.setGeometry(self.left, self.top, self.width, self.height)
                          self.show()
                  
                      def onSelectionChanged(self):
                          ca = self.calendar.selectedDate()
                          self.label.setText(ca.toString())
                  
                  App = QApplication(sys.argv)
                  window = Window()
                  sys.exit(App.exec())
                  

                  推荐答案

                  开始使用layouts

                  没有父级的小部件 - 有一个窗口.

                  A widget without a parent - there is a window.

                  import sys
                  from PyQt5 import QtCore, QtGui, QtWidgets
                  from PyQt5.QtWidgets import *
                  from PyQt5.QtCore import *
                  from PyQt5.QtGui import *
                  
                  class Window(QWidget):         #(QMainWindow):
                      def __init__(self):
                          super().__init__()
                  
                          self.title="Select date from calendar"
                          self.left, self.top, self.width, self.height  = 600, 100, 500, 480
                          self.iconName = "Ok.png"             # <--- home.png
                          self.setWindowTitle(self.title)
                          self.setWindowIcon(QtGui.QIcon(self.iconName))
                          self.setGeometry(self.left, self.top, self.width, self.height)
                  
                          self.calendar = QCalendarWidget()
                          self.calendar.setGridVisible(True)
                          self.calendar.selectionChanged.connect(self.onSelectionChanged)
                  
                          self.label = QLabel()
                          self.label.setFont(QtGui.QFont("Sanserif", 10))
                          self.label.setStyleSheet('color: blue;')
                  
                          self.proceedbutton = QPushButton("Proceed to select time", self)
                          self.proceedbutton.setToolTip("<h3>Start the Session</h3>")
                          self.proceedbutton.clicked.connect(self.window2)
                  
                          self.backbutton = QPushButton("Back", self)
                          self.backbutton.setToolTip("<h3>Start the Session</h3>")
                  
                          self.comboBox = None
                  
                          self.grid = QtWidgets.QGridLayout(self)
                          self.grid.addWidget(self.calendar, 0, 0, 1, 3)
                          self.grid.addWidget(self.label, 1, 0, 1, 3)
                          self.grid.addWidget(self.backbutton, 2, 1, 1, 1)
                          self.grid.addWidget(self.proceedbutton, 2, 2, 1, 1)
                  
                      def window2(self):
                          self.window = QWidget() 
                          self.window.setWindowTitle("Select Time")
                          self.window.setGeometry(self.left/3, self.top, self.width/3, self.height/3)
                  
                          self.label = QLabel("Select Time")                       # --- , self)
                  
                          self.comboBox = QtWidgets.QComboBox()
                          self.comboBox.addItems(["choose time", "10", "11", "12"])       
                          self.comboBox.activated[str].connect(self.onComboActivated)
                  
                          layout = QFormLayout(self.window)
                          layout.addRow('Choose Time', self.comboBox)
                  
                          self.window.show()
                  
                      def onSelectionChanged(self):
                          ca = self.calendar.selectedDate()
                          self.label.setText(ca.toString())
                  
                      def onComboActivated(self, text):
                          print("choose time: {}".format(text))
                  
                  if __name__ == '__main__':
                      App = QApplication(sys.argv)
                      window = Window()
                      window.show()
                      sys.exit(App.exec())
                  

                  这篇关于如何使用按钮打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在子进程中运行 Pyinstaller 单个可执行输出时无法 下一篇:合并 2 个编辑视频而不使用 ffmpeg 保存它们

                  相关文章

                  最新文章

                    1. <i id='HBsg6'><tr id='HBsg6'><dt id='HBsg6'><q id='HBsg6'><span id='HBsg6'><b id='HBsg6'><form id='HBsg6'><ins id='HBsg6'></ins><ul id='HBsg6'></ul><sub id='HBsg6'></sub></form><legend id='HBsg6'></legend><bdo id='HBsg6'><pre id='HBsg6'><center id='HBsg6'></center></pre></bdo></b><th id='HBsg6'></th></span></q></dt></tr></i><div id='HBsg6'><tfoot id='HBsg6'></tfoot><dl id='HBsg6'><fieldset id='HBsg6'></fieldset></dl></div>
                        <bdo id='HBsg6'></bdo><ul id='HBsg6'></ul>
                    2. <tfoot id='HBsg6'></tfoot>
                    3. <small id='HBsg6'></small><noframes id='HBsg6'>

                      <legend id='HBsg6'><style id='HBsg6'><dir id='HBsg6'><q id='HBsg6'></q></dir></style></legend>