Python Forum
Python, Tkinter, can only view partial GUI when called from another window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python, Tkinter, can only view partial GUI when called from another window
#1
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.
Reply
#2
The docs explain how to attach an image to a label http://effbot.org/tkinterbook/label.htm
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 347 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 789 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,397 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,834 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,672 Jun-26-2022, 06:26 PM
Last Post: menator01
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,866 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,548 Feb-17-2022, 07:02 AM
Last Post: pymn
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,797 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  "tkinter.TclError: NULL main window" Rama02 1 5,786 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  function in new window (tkinter) Dale22 7 4,968 Nov-24-2020, 11:28 PM
Last Post: Dale22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020