【发布时间】:2016-12-07 09:41:02
【问题描述】:
我可以让 tkinter 显示窗口或背景图像,有没有人建议如何同时显示两者(我希望对象进入背景图像),我的代码如下:
from tkinter import *
from tkinter import ttk
root= Tk()
# Code to add widgets will go here...
root.title("MTGO Daily Decklists")
def test():
print("things")
# pick a .gif image file you have in the working directory
# or give full path
image1 = PhotoImage(file="backgroundimage.gif")
w = Canvas(root, width=800, height=700,)
background = PhotoImage(file = "backgroundimage.gif")
w.create_image(500, 500, image=image1)
w.pack()
format_mtg= StringVar()
format_entry= ttk.Entry(w, width=25, textvariable=format_mtg)
format_entry_window = w.create_window(10, 10, anchor='n', window=format_entry)
format_entry.pack()
date= StringVar()
date_entry=ttk.Entry(root, width=25, textvariable=date)
date_entry_window = w.create_window(10, 10, anchor='n', window=date_entry)
date_entry.pack()
ttk.Label(w, text="input format here").pack()
ttk.Button(w, text="fetch", command=test).pack()
ttk.Label(w, text="input date here").pack()
sortby= StringVar()
sortby_entry= ttk.Entry()
sortby_entry.pack()
ttk.Label(w, text="input how you want the decklists to be sorted").pack()
root.mainloop()
【问题讨论】:
-
我没有看到任何从背景图像创建画布图像的尝试。
-
哎呀,我把 w.create_image(500, 500, image=image1) 改成了 w.create_image(500, 500, image=background) 但还是有同样的问题
-
当您将其更改为
image=background时,您是添加了一行来为image1创建画布图像,还是只创建了一个图像? -
只有一张图片,我读到您需要在某处保留对图片的引用,以便在 tkinter 关闭时不会删除它
-
如果你想打印两个对象
a和b,你试试print(a),看到它只打印a,把它改成print(b),看到它只打印b,然后推断不可能打印两件事?或者你会用print(a)写一行,然后用print(b)写另一行?
标签: python python-3.x tkinter python-imaging-library tkinter-canvas