Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:37:11+00:00 2026-05-29T22:37:11+00:00

I’m trying to make a GUI for a small program I wrote with the

  • 0

I’m trying to make a GUI for a small program I wrote with the help of some people from here, anyway, I made the GUI in PyQt and it looks fine. I added a button called dirButton that says “Choose Directory”

self.dirButton = QtGui.QPushButton(self.buttonWidget)
self.dirButton.setGeometry(QtCore.QRect(0, 0, 91, 61))
self.dirButton.setObjectName(_fromUtf8("dirButton"))
self.dirButton.clicked.connect(self.browse)

and in the bottom line there I’ve made it call self.browse when I click it, which is:

def browse(self):
    filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
    fname = open(filename)
    data = fname.read()
    self.textEdit.setText(data)
    fname.close()

However, this is the error I get:

Traceback (most recent call last):
File "C:\Users\Kevin\Desktop\python-tumblr-0.1\antearaGUI.py", line 88, in browse
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
TypeError: QFileDialog.getOpenFileName(QWidget parent=None, QString caption=QString(),     QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 1 has unexpected type 'Ui_mainWindow'

So, ui_mainWindow is the class that all of my GUI buttons and the GUI itself is stored in.

class Ui_mainWindow(object):

I don’t understand why I’m getting an error, does anyone have any ideas?

Here is a pastebin link to the entire GUI: http://pastebin.com/BWCcXxUW

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:37:12+00:00Added an answer on May 29, 2026 at 10:37 pm

    As I understand, you are using Ui_mainWindow generated from .ui file. As you can see Ui_mainWindow is just python class which contains widgets. getOpenFileName recieves QWidget instance as first parameter. So you need to subclass QWidget or QMainWindow and define methods in that class.

    Code will look like this:

    import sys
    
    from PyQt4 import QtCore, QtGui
    
    from file_with_ui import Ui_MainWindow
    
    class Main(QtGui.QMainWindow, Ui_MainWindow):
        def __init__(self):
            QtGui.QMainWindow.__init__(self)
            self.setupUi(self)
    
        def browse(self):
            filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
            fname = open(filename)
            data = fname.read()
            self.textEdit.setText(data)
            fname.close()
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        window = Main()
        window.show()
        sys.exit(app.exec_())
    

    Alternatively you can store ui as instance attribute:

    class Main(QtGui.QMainWindow):
        def __init__(self):
             QtGui.QMainWindow.__init__(self)
             self.ui=Ui_MainWindow()
             self.ui.setupUi(self)
    

    And acces your controls through self.ui, e.g.: self.ui.textEdit.setText(data)

    Consider reading tutorial about pyuic usage PyQt by Example (Session 1)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.