在tkinter阻碍Canvas剧情的背景图象

时间:2016-11-03 11:26:01

标签: python user-interface matplotlib tkinter tkinter-canvas

我是Tkinter的初学者并尝试创建一个GUI,其中有多个页面可见的背景水印(图像文件)。但是,通过Canvas的绘图应优先于水印,并在窗口上显示时可见。当前代码隐藏了水印图像(第一页)下方的画布图。如何在图像显示上更改此优先级? 以下是我的代码

   # -*- coding: utf-8 -*-
"""
Created on Thu Nov  3 15:43:02 2016
@author: tkinter beginner
"""
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg, Figure
from tkinter import *
import tkinter as tk

class Test(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand = True)
        self.frames = {}
        for F in (PageOne,PageTwo):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky="nsew")
        self.show_frame(PageOne)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()

class PageOne(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)       
        f = Figure(figsize=(5,5), dpi=100)
        a = f.add_subplot(111)
        a.plot([1,2,3,4,5,6,7,8],[5,6,1,3,8,9,3,5])
        canvas = FigureCanvasTkAgg(f, self)
        canvas.show()
        canvas.get_tk_widget().grid(row=20,column=6,sticky=W)

class PageTwo(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

root = Test()
background_image=tk.PhotoImage(file='back_img.gif')
background_label = tk.Label(root, image=background_image)
background_label.place(x=200, y=50, relwidth=1, relheight=1)

root.mainloop()

Click to see the error png

0 个答案:

没有答案