|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
《零基础入门学习Python》第65讲中老师在讲解Thinker时举的例子很生动,我在抄代码的时候有一点疑问,望大神讲解。
具体疑问在代码中有注释标明
详细代码如下:
- from tkinter import *
- def callback():
- var.set("Blow it, I don't believe it") #请问此处为什么不需要global声明
- root = Tk()
- frame1 = Frame(root)
- frame2 = Frame(root)
- var = StringVar()
- var.set("The video you downloaded contains restricted content for minors.\nPlease watch it when you are over 18 years old")
- textLabel = Label(frame1,
- textvariable = var,
- justify = LEFT)
- textLabel.pack(side = LEFT)
- photo = PhotoImage(file = "18.gif")
- imglabel = Label(frame1, image = photo)
- imglabel.pack(side = RIGHT)
- theButton = Button(frame2,
- text = "I am 18 years old",
- command = callback)
- theButton.pack()
- frame1.pack(padx = 10, pady = 10)
- frame2.pack(padx = 10, pady = 10)
- mainloop()
复制代码
|
|