Python Forum
Python, Tkinter, can only view partial GUI when called from another window - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Python, Tkinter, can only view partial GUI when called from another window (/thread-11601.html)



Python, Tkinter, can only view partial GUI when called from another window - Philia - Jul-17-2018

This is the GUI code which is actually run from another file. It calls two other Python files and executes a function from those files. The files are scan.py and webcam.py. The function from scan.py is alz_scan() and the function from webcam.py is TakeSnapAndSave().

It works fine executing those functions but the problem is I cannot see the background Image and the status bar which I coded here.
This is File1.py
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()
This function is called from the main.py file. Source code of that file:
from tkinter import *
from tkinter import PhotoImage

import File1

def needTodo():
    subMenu.add_command(label="Go", command=File1.alz)
    

def det2():
    File1.alz()

root = Tk()
root.title('........')

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

menu = Menu(root)
root.config(menu=menu)
root.minsize(600, 650)
root.geometry("600x650")

subMenu = Menu(menu)
menu.add_cascade(label="File", menu=subMenu)

subMenu.add_command(label="Go", command=needTodo)
subMenu.add_separator()
subMenu.add_command(label="Exit", command=quit)

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

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

btn2 = Button(toolbar, text="Go", command=det2)
btn2.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/background.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()
main.py runs fine and File1.py also executes the functions it is supposed to execute. But I can't see the background image and the sidebar that is supposed to be here.


RE: Python, Tkinter, can only view partial GUI when called from another window - woooee - Jul-17-2018

The docs explain how to attach an image to a label http://effbot.org/tkinterbook/label.htm