2013-02-20 34 views
0

我遍寻搜索一种方法来在Python 3中通过Tkinter GUI本地设置cookie,并且只获取不起作用的httplib2结果。在Python 3本地设置和获取Cookie 3 Tkinter

基本上我有一个简单的登录界面,这将使一个SimpleCookie:

def signIn(self): 
    user = self.login_var.get() 
    passwd = self.password_var.get() 
    C = cookies.SimpleCookie() 
    C['user'] = user 
    C['passwd'] = passwd 
    print(C.output(attrs=[], header='Cookie:')) 
    self.confirm() 

...但我不能检索/饼干传递给下一个命令:

def confirm(self): 
    self.top = Toplevel() 
    self.top.title('Congrats!') 
    self.top_frame = Frame(self.top) 
    self.top_frame.grid() 
    self.lbl = Label(self.top_frame, text='Hello ' + C['user'].value + '!') 
    self.lbl.grid() 

我确定我错过了很多东西?因为我对Python>超级新手>。 <

回答

1

可以添加一个参数,以确认这样

def confirm(self, C) 

然后用

self.confirm(C) 

在蟒称之为一个变量可以是任何对象,文字(INT,字节等)或功能甚至。

此外可以改变变量C的一类范围内的变量,它是使用

self.C = cookies.SimpleCookie() # Prefixing self. attributes with an underscore _ is commonly 
           # used to declare a soft private variable. 
           # Other classes and modules can still access it but it generally 
           # means it is not supposed to be accessed from outside the class. 

现在可以通过从类内处理C:

self.C 

和从类的外部通过:

ClassName.C 
+2

他们也可以将'C'改为'self.C'。您可能希望将其他解决方案添加到您的答案中。 – 2013-02-20 03:06:14

+0

谢谢加了一个小小的解释。 – 2013-02-20 19:42:12