我知道这可能是一个反复出现的问题,但我不明白该问题的其他答案的意义。
首先,这是我的代码(如果你想要语法高亮): http: //pastebin.com/9uJah8t2
#!/usr/bin/python2.7
from mega import Mega
import pygtk
import gtk
import glib
class HelloWorld:
#def onSuccess(self, widget, data):
def test(self, widget, data):
email = self.login.get_text()
password = self.password.get_text()
mega = Mega()
m = mega.login(email, password)
details = m.get_user()
print(details)
#get account files
files = m.get_files()
print(files)
def hello(self, widget, data=None):
print "Hello World"
def delete_event(self, widget, event, data=None):
return False
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
# Window Settings
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Mega Connector")
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.set_border_width(5)
self.window.set_resizable(False)
# Vbox
self.vbox = gtk.VBox(True, 0)
# Login
self.hboxlogin = gtk.HBox(True, 0)
self.labellogin = gtk.Label("Login")
self.hboxlogin.pack_start(self.labellogin, True, True, 0)
self.labellogin.show()
self.login = gtk.Entry(0)
self.hboxlogin.pack_start(self.login, True, True, 0)
self.login.show()
self.hboxlogin.show()
self.vbox.pack_start(self.hboxlogin, True, True, 0)
# Password
self.hboxpassword = gtk.HBox(True, 0)
self.labelpassword = gtk.Label("Password")
self.hboxpassword.pack_start(self.labelpassword, True, True, 0)
self.labelpassword.show()
self.password = gtk.Entry(0)
self.password.set_visibility(False)
self.hboxpassword.pack_start(self.password, True, True, 0)
self.password.show()
self.hboxpassword.show()
self.vbox.pack_start(self.hboxpassword, True, True, 0)
# Button
self.button = gtk.Button("Connect")
self.button.connect("clicked", self.test, None)
self.vbox.pack_start(self.button, True, True, 0)
self.button.show()
self.window.add(self.vbox)
self.vbox.show()
self.window.show()
def main(self):
gtk.main()
if __name__ == "__main__":
hello = HelloWorld()
hello.main()
这是一个非常简单的 GUI,用于登录 MEGA 并检索有关您的帐户的信息(例如上传的文件和内容)。事实是,当我单击“登录”时,GUI 会冻结,直到检索到所有信息。你能告诉我我在这个程序中做错了什么吗?
提前感谢您的回答。