从另一个窗口调用时,Python Tkinter仅能查看部分GUI

时间:2018-07-16 15:03:58

标签: python user-interface tkinter

这是实际上从另一个文件运行的GUI代码。它调用另外两个Python文件,并从这些文件执行函数。这些文件是scan.py和webcam.py。来自scan.py的功能为alz_scan(),来自webcam.py的功能为TakeSnapAndSave()

执行这些功能效果很好,但是问题是我看不到我在此处编码的背景图像和状态栏。

from tkinter import *
from tkinter import PhotoImage
import scan
import webcam



def needTodo1():
    scan.alz_scan()
def needTodo2():
    webcam.TakeSnapAndSave()
def alz():
    root = Tk()
    root.title('........')

# ******** MAIN MENU  ******** #

    menu = Menu(root)
    root.config(menu=menu)
    root.minsize(700, 600)
    root.geometry("600x500")

    subMenu = Menu(menu)
    menu.add_cascade(label="File", menu=subMenu)
    subMenu.add_command(label="Capture", command=needTodo2)
    subMenu.add_command(label="Load", command=needTodo1)
    subMenu.add_separator()
    subMenu.add_command(label="Exit", command=quit)

# *********** Toolbar ************ #

    toolbar = Frame(root, bg="blue")

    insertBar = Button(toolbar, text="Capture", command=needTodo2)
    insertBar.pack(side=RIGHT, padx=2, pady=2)

    insertBar = Button(toolbar, text="Load", command=needTodo1)
    insertBar.pack(side=RIGHT, padx=2, pady=2)

    #insertBar = Button(toolbar, text="HOME", command=needTodo)
    #insertBar.pack(side=LEFT, padx=2, pady=2)


    toolbar.pack(side=TOP, fill=X)



# ********* IMAGE BACKGROUND ************ #

    canvas = Canvas(root, width=699, height=837, bg='white')
    canvas.pack()
    gif1 = PhotoImage(file='/home/bot/Desktop/environments/my_env/img.gif')
    canvas.create_image(0, 0, image=gif1, anchor=NW)



# ********* STATUS BAR ************ #

    status = Label(root, text="It is ready to work....", bd=1, relief=SUNKEN, anchor=W)
    status.pack(side=BOTTOM, fill=X)

    root.mainloop()

0 个答案:

没有答案