Feb-09-2017, 10:31 AM
Hi there,
I have this, it works ok and I have to admit it is cobbled from things that I have found and I am still struggling with classes, I really didn't think I was that stupid.
So the second window is going to be like a contextual menu screen with a series of buttons, click on one button and the window will change to a different window taking up exactly the same space. That window will always be there but the plan was to add fuctionality to the application over time, I thought the best way was using a class for each context as one window will be a data input window, one of them will become a settings window and one will be a messageing window, all of these things I have working but only on the command line, but I am struggling with the whole classes thing still. What I was hoping was to create like a place marker that I could just drop a class into, that way the class hopefully would not interfere with the rest of the program, making the application nicely modular.
So currently, I now have worked out how to make a second window be there from a class, but I don't understand it enough to remove the button that makes it appear, I was hoping it was as simple as
I have this, it works ok and I have to admit it is cobbled from things that I have found and I am still struggling with classes, I really didn't think I was that stupid.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Qt4 tutorial using classes
This example will be built
on over time.
"""
import sys
from PyQt4 import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Window, self).__init__()
self.setGeometry(50, 50, 1600, 900)
new_window = QtGui.QPushButton("New", self)
new_window.setGeometry(QtCore.QRect(1400, 800, 120, 26))
new_window.clicked.connect(self.sub_window)
self.dialog = Form(self)
quit_btn = QtGui.QPushButton("Quit", self)
quit_btn.setGeometry(QtCore.QRect(1400, 850, 120, 26))
quit_btn.clicked.connect(self.closeEvent)
def sub_window(self):
self.dialog.show()
def closeEvent(self):
message = QtGui.QMessageBox.question(self, 'Message',
"Are you sure?",
QtGui.QMessageBox.Yes
| QtGui.QMessageBox.No,
QtGui.QMessageBox.No)
if message == QtGui.QMessageBox.Yes:
sys.exit()
else:
pass
class Form(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Form, self).__init__()
self.setGeometry(1000, 500, 300, 200)
def main():
app = QtGui.QApplication(sys.argv)
main_window = Window()
main_window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main() So the second window is going to be like a contextual menu screen with a series of buttons, click on one button and the window will change to a different window taking up exactly the same space. That window will always be there but the plan was to add fuctionality to the application over time, I thought the best way was using a class for each context as one window will be a data input window, one of them will become a settings window and one will be a messageing window, all of these things I have working but only on the command line, but I am struggling with the whole classes thing still. What I was hoping was to create like a place marker that I could just drop a class into, that way the class hopefully would not interfere with the rest of the program, making the application nicely modular.
So currently, I now have worked out how to make a second window be there from a class, but I don't understand it enough to remove the button that makes it appear, I was hoping it was as simple as
Form.show()But of course it hasn't worked, how do I now make this window be there without a button press. I just can't work it out.
