当我执行脚本时,背景图像可以正常工作,它将与窗口的大小匹配,但是,我无法显示按钮(它们尚无功能).我对python相当陌生,所以不确定是否将按钮用作事件是一个好主意.任何帮助表示赞赏.
import turtle
import tkinter as tk
from tkinter import *
from PIL import Image,ImageTk
root = Tk()
taxi = (r"C:\directory\image.png")
class App(Frame):
def __init__(self,master,Buttons=None):
Frame.__init__(self,Buttons)
self.columnconfigure(0,weight=1)
self.rowconfigure(0,weight=1)
self.original = Image.open(r"C:\directory\Layout.gif")
self.image = ImageTk.PhotoImage(self.original)
self.display = Canvas(self,bd=0,highlightthickness=0)
self.display.create_image(500,500,image=self.image,anchor=NW,tags="IMG")
self.display.grid(row=0,column=0,sticky=W+E+N+S)
self.pack(fill='both',expand=True)
self.bind("<Configure>",self.resize)
def resize(self,event):
size = (event.width,event.height)
resized = self.original.resize(size,Image.ANTIALIAS)
self.image = ImageTk.PhotoImage(resized)
self.display.delete("IMG")
self.display.create_image(0,tags="IMG")
def Buttons(self,event):
self.Button1 = tk.Button(master = root,text = "Button1") #,command = forward).pack(side = tk.LEFT)
self.Button1.grid(row=1,column=1)
self.Button2 = tk.Button(master = root,text = "Button2") #,command = forward).pack(side = tk.LEFT)
self.Button2.grid(row=2,column=1)
self.Button3 = tk.Button(master = root,text = "Button3") #,command = forward).pack(side = tk.LEFT)
self.Button3.grid(row=3,column=1)
app = App(root)
app.mainloop()