设置 URL gif 背景但不使用 Python 上的新框架 2
Setting URL gif background but not working with new frame on Python 2
我正在尝试创建一个包含主框架和三个打开新框架的按钮的程序。我能够获得 URL .gif 图像作为主框架的背景,但我很难在加载新框架时更改 URL .gif 图像。
我一直在努力弄清楚,但没有太多关于带有 URL .gif 背景的新框架 window 的信息。谁能帮我一把?谢谢
from Tkinter import*
import urllib
import base64
import Tkinter
def epl_Window():
epl = Tk()
epl.title("E")
URL = "h"
epl.a = urllib.urlopen(URL)
raw_input = epl.a.read()
epl.a.close()
c = base64.encodestring(raw_input)
image = PhotoImage(data=c)
label = Label(image=image)
label.pack()
由于与 epl_Window()
方法相关的 2 个原因,您的程序无法运行:
- 您 运行 不止一个
Tk()
- 您没有将
label
附加到 epl
解决方案
您可以通过以下方式分别解决这 2 个问题:
- 使用
Toplevel()
将行 epl = Tk()
更改为 epl = Tkinter.Toplevel()
- 将
label = Label(image = image)
更改为 label = Label(epl, image = image)
演示
应用上述修改后,您将得到这个(我点击了 3 个按钮):
奖金
- 遵循 运行
import Tkinter as Tk
的标准
- 尊重这种实例化小部件的方式:
label = Tk.Label(...)
- 应用面向对象的概念
- 关注 PEPs
我正在尝试创建一个包含主框架和三个打开新框架的按钮的程序。我能够获得 URL .gif 图像作为主框架的背景,但我很难在加载新框架时更改 URL .gif 图像。 我一直在努力弄清楚,但没有太多关于带有 URL .gif 背景的新框架 window 的信息。谁能帮我一把?谢谢
from Tkinter import*
import urllib
import base64
import Tkinter
def epl_Window():
epl = Tk()
epl.title("E")
URL = "h"
epl.a = urllib.urlopen(URL)
raw_input = epl.a.read()
epl.a.close()
c = base64.encodestring(raw_input)
image = PhotoImage(data=c)
label = Label(image=image)
label.pack()
由于与 epl_Window()
方法相关的 2 个原因,您的程序无法运行:
- 您 运行 不止一个
Tk()
- 您没有将
label
附加到epl
解决方案
您可以通过以下方式分别解决这 2 个问题:
- 使用
Toplevel()
将行epl = Tk()
更改为epl = Tkinter.Toplevel()
- 将
label = Label(image = image)
更改为label = Label(epl, image = image)
演示
应用上述修改后,您将得到这个(我点击了 3 个按钮):
奖金
- 遵循 运行
import Tkinter as Tk
的标准
- 尊重这种实例化小部件的方式:
label = Tk.Label(...)
- 应用面向对象的概念
- 关注 PEPs