【问题标题】:How to connect to a new window [duplicate]如何连接到新窗口[重复]
【发布时间】:2020-02-17 18:12:07
【问题描述】:

我试过点击。当我单击继续时,连接函数打开一个新窗口,但代码没有产生任何结果。 我正在尝试打开一个允许我选择时间的新窗口...

请帮助... :)

class Window(QDialog):
    def __init__(self):
        super().__init__()

        self.label = QLabel()
        self.calendar = QCalendarWidget()
        self.title="PyQt5 Calendar"
        self.left = 600
        self.top = 300
        self.width = 500
        self.height = 480
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        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.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.calendar.selectionChanged.connect(self.onSelectionChanged)


    def onSelectionChanged(self):
        ca = self.calendar.selectedDate()
        self.label.setText(ca.toString())

    def window2(self):
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.show()


App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())

【问题讨论】:

标签: python time pyqt5 new-window


【解决方案1】:

尝试在您的“app”类中创建一个函数,以便您可以将其作为按钮单击的命令调用,然后为您希望通过单击访问的每个页面创建一个类。类似的东西

class SeaofBTCapp(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)
        ...
        container = tk.Frame(self)
        self.frames = {}

        for F in (StartPage, PageThree):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

然后

class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)
        label = tk.Label(self, text="Start Page", font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button3 = ttk.Button(self, text="blabla",
                            command=lambda: controller.show_frame(PageThree))
        button3.pack()

【讨论】:

  • PyQt5 与 Tkinter 不同
猜你喜欢
  • 1970-01-01
  • 2022-07-01
  • 2012-11-27
  • 1970-01-01
  • 2022-11-17
  • 1970-01-01
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多