这是我实际创建这些标签或画布的代码:
class FrameBanner(tk.Frame):
"""
"""
def __init__(self, root, color_black, color_yellow, width, height):
# Initialize from parent
super(FrameBanner, self).__init__(root)
# # Left 1 Banner
# self.banner_1 = tk.Canvas(master=self, width=width*0.8, height=height, bg=color_yellow)
self.image_1 = ImageTk.PhotoImage(Image.open("images_2/logo_here.png").resize((round(width*0.7), round(height*0.9)), Image.NEAREST))
# self.banner_1.create_image(10, 10, anchor="w", image=self.image_1)
# self.banner_1.image = self.image_1
self.banner_1 = tk.Label(master=self, image=self.image_1)
self.banner_1.image = self.image_1
# # Right 2 Banner
# self.banner_2 = tk.Canvas(master=self, width=width*0.2, height=height, bg=color_black)
self.image_2 = ImageTk.PhotoImage(Image.open("images_2/logo_here.png").resize((round(width*0.15), round(height*0.9)), Image.NEAREST))
# self.banner_2.create_image(width*0.2, 10, anchor="w", image=self.image_2)
# self.banner_2.image = self.image_IMS
self.banner_2 = tk.Label(master=self, image=self.image_2)
self.banner_2.image = self.image_2
# Grid Layout
self.banner_1.grid(column=0, row=0, sticky='w')
self.banner_2.grid(column=1, row=0, sticky='e')
这是我调用它的代码:
## Banner
self.frm_banner_height = height*0.2
self.frm_banner = tk.Frame(master=self.frm_pregen, width=self.frm_pregen_width, height=self.frm_banner_height)
self.FrameBanner = FrameBanner(self.frm_banner, color_black, color_yellow, self.frm_pregen_width, self.frm_banner_height)
然后我会做:
self.frm_banner.grid(column=0, row=0)
这就是它的样子,我希望两个图像为空的角落:
有什么建议么?