Python Forum
Qt and QtPy Edit window & argument 1 has unexpected type 'Ui_MainWindow' Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Qt and QtPy Edit window & argument 1 has unexpected type 'Ui_MainWindow' Error
#7
I do not understand your concept.
You place the button somewhere in the window where you want to have the text field later.
Then either the button or the text field is not visible.
Use a toolbar and place the button there.
Or place the button in the statusbar.

Do not use something like "Exit", "Are you sure?"

Users hate that.

better ask for saving changes.

here is a simple example, choose "New" from File Menu to show the Text Field

from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QApplication, 
                             QTextEdit, QAction, QMenu, QMainWindow)
from PyQt5.QtGui import QIcon, QTextCursor, QKeySequence
from PyQt5.QtCore import Qt
import sys

class myEditor(QMainWindow):
    def __init__(self, parent = None):
        super(myEditor, self).__init__(parent)
        self.editor = QTextEdit() 
        self.editor.setTabStopWidth(20)

        bar=self.menuBar()
        self.filemenu=bar.addMenu("File")
        self.separatorAct = self.filemenu.addSeparator()
        self.filemenu.addAction(QAction(QIcon.fromTheme('document-new'), "New", self, triggered = self.newAct, shortcut = "Ctrl+n"))
        self.filemenu.addAction(QAction(QIcon.fromTheme('document-open'), "Open", self, triggered = self.openAct, shortcut = "Ctrl+o"))
        self.filemenu.addAction(QAction(QIcon.fromTheme('document-save'), "Save", self, triggered = self.saveAct, shortcut = "Ctrl+s"))
        self.filemenu.addAction(QAction(QIcon.fromTheme('document-save-as'), "Save as ...", self, triggered = self.saveAsAct, shortcut = "Shift+Ctrl+s"))
        self.filemenu.addSeparator()
        self.filemenu.addAction(QAction(QIcon.fromTheme('application-exit'), "Exit", self, triggered = self.exitAct, shortcut = "Ctrl+q"))
        
        editmenu = bar.addMenu("Edit")
        editmenu.addAction(QAction(QIcon.fromTheme('edit-undo'), "Undo", self, triggered = self.editor.undo, shortcut = "Ctrl+u"))
        editmenu.addAction(QAction(QIcon.fromTheme('edit-redo'), "Redo", self, triggered = self.editor.redo, shortcut = "Shift+Ctrl+u"))
        editmenu.addSeparator()
        editmenu.addAction(QAction(QIcon.fromTheme('edit-copy'), "Copy", self, triggered = self.editor.copy, shortcut = "Ctrl+c"))
        editmenu.addAction(QAction(QIcon.fromTheme('edit-cut'), "Cut", self, triggered = self.editor.cut, shortcut = "Ctrl+x"))
        editmenu.addAction(QAction(QIcon.fromTheme('edit-paste'), "Paste", self, triggered = self.editor.paste, shortcut = "Ctrl+v"))
        editmenu.addAction(QAction(QIcon.fromTheme('edit-delete'), "Delete", self, triggered = self.editor.cut, shortcut = "Del"))
        editmenu.addSeparator()
        editmenu.addAction(QAction(QIcon.fromTheme('edit-select-all'), "Select All", self, triggered = self.editor.selectAll, shortcut = "Ctrl+a"))

        self.layoutV = QVBoxLayout()
#        self.layoutV.addWidget(self.editor)
        mq = QWidget(self)
        mq.setLayout(self.layoutV)
        self.setCentralWidget(mq)

        self.createStatusBar()

    def createStatusBar(self):
        self.statusBar().showMessage("Ready", 0)

    def newAct(self):
        self.layoutV.addWidget(self.editor)
        self.statusBar().showMessage("TextEdit visible", 0)

    def openAct(self):
        return

    def saveAct(self):
        return

    def saveAsAct(self):
        return

    def exitAct(self):
        print("Goodbye ...")
        app.quit()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = myEditor()
#    win.setWindowIcon(QIcon.fromTheme("gnome-mime-text-x-python"))
    win.setWindowTitle("Editor")
    win.setMinimumSize(640,250)
    win.showMaximized()
    app.exec_()
Reply


Messages In This Thread
RE: Qt and QtPy Edit window & argument 1 has unexpected type 'Ui_MainWindow' Error - by Axel_Erfurt - Aug-20-2018, 02:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 854 Mar-17-2024, 09:37 AM
Last Post: deanhystad
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 921 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  [Kivy] Type error:takes 1 positional argument but 2 required hammer 3 2,837 Nov-09-2021, 06:01 AM
Last Post: deanhystad
  Syntax Error: Positional argument follows keyword argument Rama02 3 4,236 Feb-09-2021, 06:10 PM
Last Post: deanhystad
  [Tkinter] How to make message box error stay on top of window scratchmyhead 1 8,546 May-10-2020, 10:21 PM
Last Post: scratchmyhead
  tkinter window and turtle window error 1885 3 6,882 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 9,318 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020