This code works:
from PyQt4 import QtGui
import sys
app=QtGui.QApplication(sys.argv)
window1=QtGui.QWidget()
window1.show()
window2=QtGui.QWidget()
window2.show()
But this doesnt:
from PyQt4.QtGui import *
import sys
class window(QMainWindow):
def __init__(self):
super(window, self).__init__()
self.w=QWidget()
self.w.show()
app=QApplication(sys.argv)
window()
window()
How can i create 2 windows by instancing the class window? I don't get it with Qt, with Tkinter it is very easy to figure out...
EDIT: The question above is meant for creating some windows by clicking on a button in the systray. As you can see when executing the code below, it works, but there is just one window shown at any time, e.g. if i clicked twice the context menu of the systray icon to create two windows. I don't see where it comes from...
import sys
from PyQt4.QtGui import *
class Note(QMainWindow):
def __init__(self):
super(Note,self).__init__()
self.w=QWidget()
self.setWindowTitle("Note")
self.setCentralWidget(self.w)
class main():
def __init__(self):
self.app = QApplication(sys.argv)
self.trayIcon = QSystemTrayIcon(QIcon("J:\\python\\SimpleNotes.ico"), self.app)
self.menu = QMenu()
self.newWindow = self.menu.addAction("new Note")
self.separator = self.menu.addSeparator()
self.exitAction = self.menu.addAction("Exit")
self.exitAction.triggered.connect(self.close)
self.newWindow.triggered.connect(self.newNote)
self.trayIcon.setContextMenu(self.menu)
self.trayIcon.show()
self.app.exec()
def newNote(self):
print("Create new note entry has been clicked")
self.note=Note()
self.note.show()
def close(self):
self.trayIcon.hide()
self.app.exit()
print("Exit menu entry has been clicked")
main()
EDIT2: Got it! The problem can be solved by coding it this way:
class main():
def __init__(self):
self.notes=[]
...
def newNote(self):
note=Note()
note.show()
self.notes.append(note)
Though still I don't know why now it works, or even no window occurs if you delete the line "self.notes.append(note)". But hah, it works!