将字符串传递给pyqt应用程序

时间:2015-03-17 22:50:54

标签: python qt pyqt qtgui

我正在编写一个pyqt应用程序,它将在密码保护的网站后面获取一个wifi密码,我想写一个qt应用程序,它将使用该表单为我的python脚本提供用户名和密码,然后返回所有信息回来并把它放在我之前留空的标签中。 这是Qt代码:

from PyQt4.QtGui import QApplication, QWidget, QLabel, QComboBox, QLineEdit, QPushButton
    import sys
    import wifiRetriever

    qt_app = QApplication(sys.argv)

    class pyGui(QWidget):

        def __init__(self):
            # Initialize the object as a QWidget
            QWidget.__init__(self)

            # We have to set the size of the main window
            # ourselves, since we control the entire layout
            self.setMinimumSize(400, 185)
            self.setWindowTitle('some Public Wifi')

            # Create the controls with this object as their parent and set
            # their position individually; each row is a label followed by
            # another control

            # Label for the username field
            self.username_lbl = QLabel('Username', self)
            self.username_lbl.move(5, 5)

            self.username = QLineEdit(self)
            self.username.setPlaceholderText("some Username")

            # Allow 100px for the label and 5px each for borders at the
            # far left, between the label and the combobox, and at the far
            # right
            self.username.setMinimumWidth(285)
            # Place it five pixels to the right of the end of the label
            self.username.move(110, 5)

            # The label for the password
            self.password_lbl = QLabel('Password:', self)
            # 5 pixel indent, 25 pixels lower than last pair of widgets
            self.password_lbl.move(5, 50)

            # The recipient control is an entry textbox
            self.password = QLineEdit(self)
            # Add some ghost text to indicate what sort of thing to enter
            self.password.setPlaceholderText("some Password")
            # Same width as the salutation
            self.password.setMinimumWidth(285)
            # Same indent as salutation but 25 pixels lower
            self.password.move(110, 50)
            # Hide the Characters
            self.password.setEchoMode(QLineEdit.Password)

            # The label for the greeting widget
            self.guestWifi_lbl = QLabel('Guest Wifi Password is:', self)
            # Same indent as the others, but 45 pixels lower so it has
            # physical separation, indicating difference of function
            self.guestWifi_lbl.move(5, 100)

            # The greeting widget is also a label
            self.greeting = QLabel('', self)
            # Same indent as the other controls
            self.greeting.move(175, 100)

            # The build button is a push button
            self.build_button = QPushButton('Submit', self)

            # Place it at the bottom right, narrower than
            # the other interactive widgets
            self.build_button.setMinimumWidth(145)
            self.build_button.move(250, 150)

        def run(self):
            # Show the form
            self.show()
            # Run the Qt application
            qt_app.exec_()
    app = pyGui()
    app.run()`

这是python脚本,(我知道这是有效的,因为我正在运行它作为已打印值而不是返回它的脚本。)

#! /usr/bin/python2.7
import urllib2
import getpass
from BeautifulSoup import BeautifulSoup
import re
def getWifiPassword(username, password):
    url = 'someurl'
    # username = getpass._raw_input('What is your username?: ')
    # password = getpass.unix_getpass('Password: ')
    p = urllib2.HTTPPasswordMgrWithDefaultRealm()

    p.add_password(None, url, username, password)

    handler = urllib2.HTTPBasicAuthHandler(p)
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)

    page = urllib2.urlopen(url).read()
    soup = BeautifulSoup(page)

    data = soup.findAll('strong')
    for d in data:
        value= re.sub("<.*?>", "", str(d))
        return value

任何帮助都会非常感激,因为qt和gtk似乎真的踢我的屁股。谢谢!

0 个答案:

没有答案