当用户按下登录按钮并且用户名和密码正确时,我试图将一些数据(如用户名)输出到gui ...我想知道的是将数据从此代码导出到gui的过程喜欢在“boxWelcome”对象中使用“欢迎”,我想显示“welcome $ username”(下面是我的python代码,这是我的glade文件http://dl.dropbox.com/u/12934567/Login.glade)
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
except:
print("GTK Not Availible")
sys.exit(1)
class login:
def __init__( self):
return None
def giveResult( self,username,password ):
print username
if username == nitin and password == sharma:
return 1
else:
return 0
class loginGui:
def __init__( self ):
self.builder = gtk.Builder()
self.builder.add_from_file("Login.glade")
dic = {
"on_buttonExit_clicked" : self.exit,
"on_buttonLogin_clicked" : self.checkLogin,
"on_windowMain_destroy" : self.exit,
}
self.builder.connect_signals( dic )
def checkLogin(self, widget):
username = self.builder.get_object ("entryUsername")
password = self.builder.get_object ("entryPassword")
try:
if (username.get_text() == 'nitin' and password.get_text()== 'sharma'):
self.builder.get_object("boxWelcome").show()
self.builder.get_object ("boxWarning").hide()
else:
self.builder.get_object("boxWarning").show()
self.builder.get_object ("boxWelcome").hide()
except ValueError:
#self.builder.get_object("hboxWarning").show()
#self.builder.get_object("entryResult").set_text("ERROR")
return 0
#self.builder.get_object("hboxWarning").hide()
#self.builder.get_object("image1").hide()
#self.builder.get_object("entryResult").set_text(thistime.giveResult())
def exit(self, widget):
sys.exit(0)
loginGui = loginGui()
gtk.main()
答案 0 :(得分:0)
为什么不在显示之前设置它?
self.builder.get_object("boxWelcome").set_text("Welcome %s!" % (username.get_text()))