Feb-12-2020, 09:55 PM
To test it I've changed it. I have no PySide2
[PyQt] timer makes my qmessagebox crash
|
Feb-12-2020, 09:55 PM
To test it I've changed it. I have no PySide2
(Feb-12-2020, 07:10 PM)Denni Wrote: Hey @Axel_Erfurt if you going to give an example why provide something that does not fully reflect proper design? I usually use tkinter but this time i was a bit lazy an thought why not try out pyside2 and the designer. ![]()
Oh sorry I did not realize that -- I was redesigning the solution Axel_Erfurt had put forth just to create a more python-qt-ish example. As for having your GUI design being separate from the App that is perfectly fine -- just when you subclass QMainWindow put it within its own separate file -- easy peasy
@Axel_Erfurt I do not have PySide2 either I do all my coding in PyQt5 then simply replace the reference to PyQt5 with PySide2 this works about 95% of the time -- the only discrepancy I have come across is PyQt5 uses pyqtSignal and pyqtSlot while PySide2 references these as just Signal and Slot. (Feb-14-2020, 04:49 PM)Denni Wrote: Oh sorry I did not realize that -- I was redesigning the solution Axel_Erfurt had put forth just to create a more python-qt-ish example. As for having your GUI design being separate from the App that is perfectly fine -- just when you subclass QMainWindow put it within its own separate file -- easy peasy Here is something i put together in a hurry in tkinter yesterday it works like my pyside2 app. import sys from datetime import datetime from threading import Timer import tkinter as tk from tkinter import messagebox class HomePage(tk.Tk): def __init__(self): super().__init__() self.geometry("200x140+10+10") self.frame = tk.Frame(self) self.frame.master.title("Tkinter") self.frame.grid(padx=13, pady=13) self.createWidgets() def createWidgets(self): self.a1 = tk.IntVar() self.a2 = tk.IntVar() self.a3 = tk.IntVar() self.textmsg = tk.StringVar() self.myLabelH = tk.Label(self.frame, text="Hour") Hour = tk.Entry(self.frame, font=('Helvetica', 12, 'bold'), textvariable=self.a1, width = 5) self.myLabel2 = tk.Label(self.frame, text=":") self.myLabelM = tk.Label(self.frame, text="Minutes") Minutes = tk.Entry(self.frame, font=('Helvetica', 12, 'bold'), textvariable=self.a2, width = 5) self.myLabel3 = tk.Label(self.frame, text=":") self.myLabelS = tk.Label(self.frame, text="Seconds") Seconds = tk.Entry(self.frame, font=('Helvetica', 12, 'bold'), textvariable=self.a3, width = 5) self.myLabelmessage = tk.Label(self.frame, text="Text message") textmessage = tk.Entry(self.frame, font=('Helvetica', 12, 'bold'), textvariable=self.textmsg, width = 19) button1 = tk.Button(self.frame, text="Make", command=self.ok_handler, width = 24) self.myLabelH.grid(row=1, column=0) self.myLabelM.grid(row=1, column=2) self.myLabelS.grid(row=1, column=4) self.myLabel2.grid(row=2, column=1) self.myLabel3.grid(row=2, column=3) Hour.grid(column=0, row=2, sticky=(tk.W)) Minutes.grid(column=2, row=2, sticky=(tk.W)) Seconds.grid(column=4, row=2, sticky=(tk.W)) self.myLabelmessage.grid(row=3, column=1, columnspan=3, sticky=(tk.W)) textmessage.grid(column=0, row=4, sticky=(tk.W), columnspan=5) button1.grid(column=0, row=5, sticky=(tk.W), columnspan=5, pady = 5) def ok_handler(self): x=datetime.today() y=x.replace(day=x.day+1, hour=(self.a1.get()), minute=(self.a2.get()), second=(self.a3.get()), microsecond=0) delta_t=y-x secs=delta_t.seconds+1 t = Timer(secs, self.hello_world) t.daemon = True t.start() def hello_world(self): value1 = (self.textmsg.get()) print (value1) messagebox.showinfo("Title", value1) def main(): app = HomePage() app.mainloop() if __name__ == '__main__': main()
Okay so do you want that re-written in PySide2 or is that just an FYI?
Feb-19-2020, 05:06 PM
Okay not exactly what you created but it should give you an idea of the how to -- also as I state in code you could have used a QGridLayout but I figured I would show the more free-form method as folks seem to have more trouble with that than using the more static Grid version. Also I did not implement the Message Box as there are plenty of examples of how to do that out there and I was not sure what yours was supposed to be doing. I hope this helps you with understanding PySide2 (or PyQt for that mattter as I used PyQt to make this then just referenced it to PySide2)
from PySide2.QtCore import Slot from PySide2.QtGui import QFont from PySide2.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout from PySide2.QtWidgets import QPushButton from datetime import datetime as dtDateTime class DoubleLabel(QWidget): def __init__(self, Text, Value=''): QWidget.__init__(self) Font = QFont() Font.setFamily('Helvetica') Font.setPointSize(12) Font.setBold(True) self.lblText = QLabel(Text) self.lblText.setFont(Font) self.lblValu = QLabel(str(Value)) self.lblValu.setFont(Font) HBox = QHBoxLayout() HBox.addWidget(self.lblText) HBox.addWidget(self.lblValu) HBox.addStretch(1) self.setLayout(HBox) def SetValue(self, Value): self.lblValu.setText(str(Value)) class HomePage(QWidget): def __init__(self): # Note unless you fully understand the 3 major issues you create by using # Super( ) you should not use it for the rather rare case it was designed for QWidget.__init__(self) self.setWindowTitle('PySide2') Top = 200; Left = 700; Wdth = 250; Hght = 100 self.setGeometry(Left, Top, Wdth, Hght) self.Hour = 0 self.Mnut = 0 self.Scnd = 0 self.Cntr = 0 self.btnMake = QPushButton('Update') self.btnMake.clicked.connect(self.Updater) self.btnHllo = QPushButton('Hello') self.btnHllo.clicked.connect(self.Holler) # Note one could also use a GridLayout as well HBox1 = QHBoxLayout() HBox1.addStretch(1) HBox1.addWidget(self.btnMake) HBox1.addWidget(self.btnHllo) HBox1.addStretch(1) self.lblMesg = QLabel('Text Message Goes Here') VBox1 = QVBoxLayout() VBox1.addWidget(self.lblMesg) VBox1.addLayout(HBox1) VBox1.addStretch(1) HBox2 = QHBoxLayout() HBox2.addLayout(VBox1) HBox2.addStretch(1) self.lblHour = DoubleLabel('Hours :') self.lblMnut = DoubleLabel('Minutes :') self.lblScnd = DoubleLabel('Seconds :') VBox2 = QVBoxLayout() VBox2.addWidget(self.lblHour) VBox2.addWidget(self.lblMnut) VBox2.addWidget(self.lblScnd) VBox2.addWidget(QLabel(' ')) VBox2.addLayout(HBox2) VBox2.addStretch(1) self.setLayout(VBox2) @Slot() def Updater(self): Today = dtDateTime.today() self.Hour = Today.hour self.Mnut = Today.minute self.Scnd = Today.second self.lblHour.SetValue(str(self.Hour)) self.lblMnut.SetValue(str(self.Mnut)) self.lblScnd.SetValue(str(self.Scnd)) @Slot() def Holler(self): self.Cntr += 1 Msg = 'Well Hello to you : '+ str(self.Cntr) self.lblMesg.setText(Msg) if __name__ == '__main__': MainEvntHndlr = QApplication([]) MainApp = HomePage() MainApp.show() MainEvntHndlr.exec()
Feb-19-2020, 07:11 PM
(Feb-19-2020, 06:55 PM)Denni Wrote: Okay while not perhaps exactly what you created it should give an idea of the how to -- also as I state in code you could have used a QGridLayout but I figured I would show the more free-form method as folks seem to have more trouble with that than using the more static Grid version. Also I did not implement the Message Box as there are plenty examples of how to do that out there and I was not sure what yours was supposed to be doing. I hope this helps you with understanding PySide2 (or PyQt for that mattter as I used PyQt to make this then just referenced it to PySide2) Thank you. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
![]() |
[PyQt] Qt app won't crash after sys.excepthook override | Alfalfa | 3 | 3,806 |
Dec-28-2020, 01:55 AM Last Post: deanhystad |
[PyQt] Customizing QMessageBox | arbiel | 1 | 8,289 |
Dec-16-2020, 08:57 PM Last Post: Axel_Erfurt |
|
PY TO EXE CRASH | kozaizsvemira | 0 | 2,840 |
Oct-19-2019, 07:27 PM Last Post: kozaizsvemira |
|
(pyQt/pySide)setStyleSheet(border…) makes QPushButton not clickable in Maya | vladlenPy | 0 | 5,402 |
Apr-15-2018, 12:41 PM Last Post: vladlenPy |
|
[PyQt] SOLVED QMessageBox: can't get QMessageBox.Yes to work | Fred Barclay | 0 | 6,803 |
May-18-2017, 06:07 AM Last Post: Fred Barclay |