I have a drop down menu girded on my calculator and i have it set so that there is 3 menu items. What i want to happen is that when one of the menu items is selected it opens a toplevel window describing that item menu and each one is a different menu because they contain different things how can i code this to happen. Im stuck with setting it so that it opens different window for when a different one is slected.
def change_dropdown(*args):
top = Toplevel()
top.title("READ")
toplabel = Label(top,text= "Lmao", font = ("Helvetica", 13))
toplabel.grid()
button = Button(top, text="Dismiss", relief=FLAT, font = ("Helvetica", 10, "bold"), fg = "ghostwhite", bg = "black", width = "30", height = "2", command=top.destroy)
button.grid()
top.focus()
def popmenu():
global tkvar
tkvar = StringVar(master)
choices = {"About","Colour themes", "Contact",}
popupMenu = OptionMenu(master, tkvar, *choices)
popupMenu.grid(row = 0, column = 0, columnspan = 5, sticky=W+E+S+N)
tkvar.set("About")
tkvar.trace("w", change_dropdown)
As far as I can understand, you want something like this...
def change_dropdown(*args):
if tkvar.get() == "About":
# open About window
elif tkvar.get() == "Contact":
# open Contact window
...., etc
Complete example
Each Toplevel window is a window like the root window and you put widgets on it just like on master.
I changed the code a bit to make it more readable from my point of view; I lifted the main window (master) code from the function. I put font specs in the beginning to make the Labels and Buttons code shorter. I changed the Dict choices to a Tuple which feels more natural. I gave the OptionMenu a width to keep it from changing size with chosen selection.
from tkinter import *
master = Tk()
master.geometry('300x150+1000+50')
info = Label(master, text='Press "p" for popup menu')
info.pack()
# Fonts
H13 = ("Helvetica", 13)
H10B = ("Helvetica", 10, "bold")
def change_dropdown(*args):
top = Toplevel()
if tkvar.get() == "About": # About window
top.title("About")
toplabel = Label(top,text= "The About window", font = H13)
toplabel.grid()
button = Button(top, text="Dismiss", relief=FLAT, font = H10B,
fg = "ghostwhite", bg = "black", width = "30",
height = "2", command=top.destroy)
button.grid()
top.focus()
elif tkvar.get() == "Contact": # Contact window
top.title("Contact")
toplabel = Label(top,text= "Contact form", font = H13)
toplabel.grid()
button = Button(top, text="Dismiss", relief=FLAT, font = H10B,
fg = "ghostwhite", bg = "black", width = "30",
height = "2", command=top.destroy)
button.grid()
top.focus()
elif tkvar.get() == "Colour themes": # Color themes window
top.title("Colour themes")
toplabel = Label(top,text= "Choose color theme", font = H13)
toplabel.grid()
button = Button(top, text="Dismiss", relief=FLAT, font = H10B,
fg = "ghostwhite", bg = "black", width = "30",
height = "2", command=top.destroy)
button.grid()
top.focus()
tkvar = StringVar(master)
def popmenu(event):
top = Toplevel()
choices = ("About","Colour themes", "Contact") # Tuple or List instead of dict
popupMenu = OptionMenu(top, tkvar, *choices)
popupMenu.config(width=15) # Otherwise width varies with option
popupMenu.grid(row = 0, column = 0, columnspan = 5, sticky=W+E+S+N)
tkvar.set("Pick one")
tkvar.trace("w", change_dropdown)
master.bind('p', popmenu)
master.mainloop()
This is a very simple interface, but if you plan on making it more complex I strongly suggest you read up on Object Oriented Python. Keeping track of globals gets difficult pretty quick.
Related
I have been making this downloader app in python using tkinter and tkinter.ttk and added a recent feature in the app for the users to see a log of previous actions done by the program. It works fine, however, I recently discovered a bug.
I have a settings button which creates another Toplevel and then you can manage the default directories and change the switch the mode of the app to light or night mode or a custom theme using three ttk.Radiobuttons but whenever I hit the first two radiobuttons (the first two are responsible for switching the theme from light mode to dark mode and vise versa) my ttk.treeview's width gets added by one for no reason. the strange part is that it does not happen to the third radiobutton, responsible for making a custom mode.
I tried setting a maxsize for the log's toplevel but it is affecting the ttk.treeview itself. Why is this happening? How can I prevent this?
A simulation of my app (this is just a demonstration so I didn't write the entire theme code):
from tkinter import *
from tkinter import colorchooser
from tkinter import ttk
columns = ("Operation", "URL", "File Path", "Status", "Start Date", "End Date")
log_data = [("Download (File)", "https://www.youtube.com", "C:/Users/Mypc/Downloads/youtube.html", "Finished", "2021-03-30 13:15:30", "2021-03-30 13:15:33"),
("Format Fetch", "https://www.youtube.com/watch?v=xxNxqveseyI", "------", "Finished", "2021-03-30 13:15:30", "2021-03-30 13:15:33")]
font_color, bg_color = "black", "white"
root = Tk()
root.configure(bg=bg_color)
root.resizable(False, False)
night_on = IntVar(value=1)
style = ttk.Style()
style.configure("Treeview", rowheight=25, font=('Arial', 10))
style.configure("Treeview.Heading", font=('Arial', 10))
style.configure("TLabel", foreground=font_color, background=bg_color)
style.configure('my.TButton', font=('Helvetica', 20, 'italic'))
style.configure("TRadiobutton", foreground=font_color, background=bg_color, font=('Arial', 10))
font_color_var = StringVar(value=f"Current font color: \t {font_color}")
bg_color_var = StringVar(value=f"Current background color: \t {bg_color}")
log_top = Toplevel(root)
log_top.withdraw()
log_top.resizable(False, False)
log_fr = Frame(log_top)
log_scroll = ttk.Scrollbar(log_fr, orient=VERTICAL)
log_tree = ttk.Treeview(log_fr, selectmode="browse", yscrollcommand=log_scroll.set, height=12, columns=columns)
log_scroll.config(command=log_tree.yview)
def clear_records():
for child in log_tree.get_children():
log_tree.delete(child)
clr_log_btn = ttk.Button(log_top, text="Clear Log", takefocus=False, style="my.TButton", command=clear_records)
log_tree.column("#0", width=0, stretch=NO)
log_tree.column("Operation", width=100, anchor=CENTER)
log_tree.column("URL", width=100, anchor=CENTER)
log_tree.column("File Path", width=100, anchor=CENTER)
log_tree.column("Status", width=80, anchor=CENTER)
log_tree.column("Start Date", width=126, anchor=CENTER)
log_tree.column("End Date", width=126, anchor=CENTER)
for head in columns:
log_tree.heading(head, text=head, anchor=CENTER)
for item_indices, element in enumerate(log_data):
log_tree.insert(parent='', index=0, iid=item_indices, values=element)
log_tree.pack(side=LEFT)
log_scroll.pack(side=RIGHT, fill=Y)
clr_log_btn.pack(side=BOTTOM, fill=X)
log_fr.pack()
log_top.protocol("WM_DELETE_WINDOW", log_top.withdraw)
log_lbl = Label(root, text="Show Log", fg="blue", bg=bg_color, cursor="hand2")
def show_log(event):
if log_top.state() == "withdrawn":
log_top.deiconify()
elif log_top.state() == "normal":
log_top.focus_set()
def settings_win():
settings_top = Toplevel(root, bg=bg_color)
settings_top.resizable(False, False)
def set_night():
global bg_color, font_color
bg_color = "black"
font_color = "white"
settings_top.config(bg=bg_color)
style.configure("TLabel", foreground=font_color, background=bg_color)
style.configure("TRadiobutton", foreground=font_color, background=bg_color)
def set_light():
global bg_color, font_color
bg_color = "white"
font_color = "black"
settings_top.config(bg=bg_color)
style.configure("TLabel", foreground=font_color, background=bg_color)
style.configure("TRadiobutton", foreground=font_color, background=bg_color)
def set_custom():
global font_color, bg_color
color_fr = Toplevel(root, bg=bg_color)
color_fr.resizable(False, False)
current_font_color = ttk.Label(color_fr, textvariable=font_color_var)
current_bg_color = ttk.Label(color_fr, textvariable=bg_color_var)
def change_color(name):
global font_color, bg_color
new_color = colorchooser.askcolor()[1]
if new_color is not None:
if name == "font":
font_color = new_color
font_color_var.set(f"Current font color: \t {font_color}")
style.configure("TLabel", foreground=font_color)
style.configure("TRadiobutton", foreground=font_color)
elif name == "bg":
bg_color = new_color
bg_color_var.set(f"Current background color: \t {bg_color}")
color_fr.config(bg=bg_color)
style.configure("TLabel", background=bg_color)
style.configure("TRadiobutton", background=bg_color)
change_font = ttk.Button(color_fr, text="Change! ", command=lambda: change_color("font"),
takefocus=False)
change_bg = ttk.Button(color_fr, text="Change! ", command=lambda: change_color("bg"), takefocus=False)
current_font_color.grid(row=0, column=0, pady=(10, 0), padx=5)
change_font.grid(row=0, column=1, padx=(0, 7))
current_bg_color.grid(row=1, column=0, pady=(10, 0), padx=5)
change_bg.grid(row=1, column=1, padx=(0, 7))
night_mode = ttk.Radiobutton(settings_top, text="Night Mode", variable=night_on, value=0,
command=set_night, takefocus=False)
light_mode = ttk.Radiobutton(settings_top, text="Light Mode", variable=night_on, value=1,
command=set_light, takefocus=False)
custom_mode = ttk.Radiobutton(settings_top, text="Custom Mode", variable=night_on, value=2,
command=set_custom, takefocus=False)
night_mode.grid(row=0, column=0)
light_mode.grid(row=1, column=0)
custom_mode.grid(row=2, column=0)
log_lbl.bind("<Button-1>", show_log)
log_lbl.pack(side=LEFT, pady=30, padx=30)
settings_btn = ttk.Button(root, text="Open Settings", takefocus=False, command=settings_win)
settings_btn.pack(side=RIGHT, padx=30, pady=30)
root.focus_set()
root.mainloop()
I think I worked out a way to solve your problem. First, I minified your code to make it easier to debug:
import tkinter as tk
from tkinter import ttk
columns = ("1", "2", "3")
font_color, bg_color = "black", "white"
def change_theme():
global bg_color, font_color
# Switches the values of `bg_color` and `font_color`
bg_color, font_color = font_color, bg_color
root.config(bg=bg_color)
style.configure("TLabel", fg=font_color, bg=bg_color)
root = tk.Tk()
style = ttk.Style()
tree = ttk.Treeview(root, columns=columns)
tree.pack()
button = tk.Button(root, text="Click me", command=change_theme)
button.pack()
root.mainloop()
After looking at your code again I noticed that you had stretch=NO which is the same as stretch=False for the #0 heading. I desided to apply it to all of the heading like this:
tree.column("#0", stretch=False)
for column_name in columns:
tree.column(column_name, stretch=False)
And it solved your problem. After looking at this documentation for ttk.TreeView I noticed what it said about the stretch parameter: "If this option is True, the column's width will be adjusted when the widget is resized. The default setting is 1." From that I concluded that for some reason style.configure("TLabel", ...) changes the width of the treeview triggering all of the columns to resize.
I don't know enough about TreeView and Styles to tell you why this happens but if someone knows they can edit my answer.
I'm trying to add an image in a Top Level window in python, however I can't seem to get it working.
I've tried using canvases and following some other steps on stack overflow. One thing I haven't tried is using class, init and self, but I don't really understand that, and hoping I can acheive my thing without the use of self. and stuff like that :D.
def pika():
def close():
win.destroy()
win = Toplevel()
win.geometry("150x150")
win.title("I CHOOSE U")
yellowb = Label(win, bg = 'yellow', fg = 'yellow', padx = 100, pady = 100)
yellowb.pack()
poke = PhotoImage(file = "pika.gif")
pika = Label(image = poke) # REEEEEEEEEEEEEEEEEE IT NO WORKEY
pika.grid(row = 0, column=1, padx = 10, pady = 10)
button = Button(win, text = "Close", command = close)
button.place(x=49, y=130)
Heres the main windows code
win = Tk()
win.geometry("290x200")
win.title('Error')
text1 = Label(win, bg= "Cyan", fg = 'Teal', padx = 50, pady = 75, text = '#hash error',
font = ('Times', '40', 'bold'))
text1.place(x=win.winfo_width() / 2, y=win.winfo_width() / 2)
button1 = Button(win, text = 'green', command = green)
button1.place(x=40, y=160)
button2 = Button(win, text = 'blue', command = blue)
button2.place(x=90, y=160)
button3 = Button(win, text = "red", command = red)
button3.place(x=130, y=160)
button4 = Button(win, text = 'yellow', command = yellow)
button4.place(x=170, y=160)
button5 = Button(win, text = "orange", command = orange)
button5.place(x=229, y=160)
eggs = PhotoImage(file = "pika.gif")
eggpic = Button(win, image = eggs, bg = 'Cyan', fg = 'Cyan', command = pika)
eggpic.place(x=100, y=20)
def close():
win.destroy()
closebut = Button(win, text='close', command = close)
closebut.place(x=0, y=0)
When I click a button and it opens a new windows the bg of the windows is yellow and everything as intended, however the image doesn't appear on the windows, and a white box the size of the image appears in the main tk window.
https://imgur.com/a/XU5m3Se
You can have two problems:
First: Every widget needs parent. If you don't use it then tkinter assigs widget to main window.
And you have this problem in Label(image = poke) because you forgot win in
pika = Label(win, image=poke)
This is why you see rectangle in main window instead of toplevel window.
Second: There is bug in PhotoImage. Garbage Collector removes it from memory when it is created in function and assigned to local variable. And then you can see empty image.
You have to assign PhotoImage to global variable or assign to other widget in function.
Popular solution with assigning to other widget:
poke = PhotoImage(file = "pika.gif")
pika = Label(win, image=poke)
pika.photo = poke # <-- assign PhotoImage to other widget too
More: PhotoImage
I have a python GUI code to open and close. I need to modify the code like when I press the open button the button colour turns into green and when I press close button the open button colour changes to its default colour.
from serial import*
from time import*
from tkinter import*
window = Tk()
def open_command():
print("Opening")
def close_command():
print("Closing")
b = Button(window, text = "Open", font = ("Times New Roman", 12), fg = "green", bg = "white", height = 1, width = 5, command = open_command).pack()
b = Button(window, text = "Close", font = ("Times New Roman", 12), fg = "red", bg = "white", height = 1, width = 5, command = close_command).pack()
mainloop()
when clicking open button colour of open button needs to change from its default colour to green. If we click close button close button colour needs to change red and open button colour changes to its default colour.
You can simply use .config(bg=...) to change the background color of the button to whatever color you want as below:
import tkinter as tk
window = tk.Tk()
def open_command():
open_btn.config(bg='green')
close_btn.config(bg='white')
def close_command():
open_btn.config(bg='white')
close_btn.config(bg='red')
font=('Times New Roman', 12)
open_btn = tk.Button(window, text='Open', font=font, fg='green', bg='white', width=5, command=open_command)
open_btn.pack()
close_btn = tk.Button(window, text='Close', font=font, fg='red', bg='white', width=5, command=close_command)
close_btn.pack()
window.mainloop()
I am creating a word editor in which I would like a taskbar at the top which has an OptionMenu widget with 3 possible choices - "right", "left", and "center". When one of these choices are chosen, it should take the value of that choice and set a text box window to each of those values using .tag_add, .insert, and .tag_config. Here is my code so far. All of it is inside of a frame called Task1, and the text box itself is inside a frame called label_frame. Next, the taskbar and the OptionMenu widget is inside a frame called Taskbar1. Here is my full code, which makes the GUI work.
from tkinter import *
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
import tkinter as tk
from tkinter import Menu, filedialog
root = Tk()
class ToDoList(tk.Frame):
def __init__(self, master):
root.columnconfigure(2, weight=1)
root.rowconfigure(1, weight=1)
root.title("To - Do List")
root.geometry("1200x600")
root.configure(background = "white")
# Variable list:
style = ttk.Style()
current_theme =style.theme_use()
style.theme_settings(current_theme, {"TNotebook.Tab": {"configure": {"padding": [20, 5], "background" : "white"}}})
style.theme_settings(current_theme, {"TNotebook" : {"configure" : {"tabposition" : "wn", "padding" : (0, 5)}}})
style.theme_settings(current_theme, {"TNotebook.Window" : {"configure" : {"width" : 500}}})
TasksList = ttk.Notebook(root)
Task1 = tk.Frame(TasksList, bg='white', height = 1000, width = 3000)
Taskbar1 = tk.Frame(Task1, bg="white", width=176)
Taskbar1.pack()
Button(Taskbar1, text="Hello", highlightthickness=0, borderwidth=0, highlightbackground = "white").pack(pady=[4, 5], padx=[3,3], ipadx = [2], ipady = [2], side = LEFT)
JustifyOptionList = ["right", "center", "left"]
JustifyDefaultOption=StringVar(Taskbar1)
JustifyDefaultOption.set(JustifyOptionList[0]) # default choice
JustifyOption= OptionMenu(Taskbar1, JustifyDefaultOption, *JustifyOptionList)
JustifyOption.pack(side = LEFT)
JustifyDefaultOption
entry1 = Entry(Task1, width = 60, font = "Calibri 20", highlightthickness = 0, justify = "center", selectborderwidth = 0, bd = 1, borderwidth = 0, relief = FLAT)
entry1.pack()
label_frame = tk.Frame(Task1, width=1000,height=550,bg="blue")
label_frame.pack()
label_frame.columnconfigure(0, weight=2)
label_frame.rowconfigure(0, weight = 1)
label_frame.pack_propagate(0)
# create a Text widget
root.txt = tk.Text(label_frame)
root.txt.config(font=("TkMenuFont"), undo=True, wrap='word', highlightthickness=0, borderwidth=0, bd = 1, highlightbackground = "white", spacing1 = 5, spacing2 = 5, spacing3 = 5)
root.txt.tag_config(JustifyDefaultOption.get(), justify = JustifyDefaultOption.get())
root.txt.insert("1.0", "Please enter your notes here")
root.txt.tag_add(JustifyDefaultOption.get(), "1.0", "end")
root.txt.pack(expand=TRUE, fill = "both", side = LEFT)
# create a Scrollbar and associate it with txt
scrollb = tk.Scrollbar(label_frame, command=root.txt.yview, width = 16, bg = "white", troughcolor = "white", highlightbackground = "white")
scrollb.pack(fill = Y, side = RIGHT)
root.txt['yscrollcommand'] = scrollb.set
Task2 = tk.Frame(TasksList, bg='white')
text=ScrolledText(Task2, width = 176, height = 120, font = "TkMenuFont")
text.grid(row = 2, column = 0)
entry2 = Entry(Task2, width = 179, font = "TkMenuFont")
entry2.grid(row=0, column=0, sticky = W)
Task3 = tk.Frame(TasksList, bg = "white")
text=ScrolledText(Task3, width = 176, height = 120, font = "TkMenuFont")
text.grid(row = 2, column = 0)
entry3 = Entry(Task3, width = 179, font = "TkMenuFont")
entry3.grid(row=0, column=0, sticky = W)
TasksList.add(Task1,text = 'Click Here In Order To Read The Instructions')
TasksList.add(Task2, text = 'Two Two Two Two Two Two'[0: 40] + '...')
TasksList.add(Task3, text = "Three Three Three Three Three Three Three Extra"[0 : 40] + '...')
TasksList.grid(row=1, column=0, sticky=N+W, columnspan=3)
Button(root, text = "WELCOME", borderwidth=0, highlightthickness=0).grid(row=0, column=1, sticky=E, ipady = [5])
Label(text="HELLO", borderwidth=0, highlightthickness=0).grid(row=0, column=0, sticky=W, ipady = [5])
root.mainloop()
The part that I am confused about regarding this is the fact that even though I have a OptionList that records the option that the user selects, this option is not set in the justify settings even though I am using a .get function to take the user's justify setting and apply it to the text box.
The problem is that you do not change the justify setting each time the option changes. Initializing with .get does not make the value update when the StringVar value changes.
One way of applying the new justify setting to the text is to use the command option of the OptionMenu to do it:
import tkinter as tk
def justify_text(option):
"""Change text justify setting."""
text.tag_configure('justify', justify=option)
# make sure all text has the tag
text.tag_add('justify', '1.0', 'end')
root = tk.Tk()
options = ["right", "center", "left"]
var = tk.StringVar(root, options[0])
menu = tk.OptionMenu(root, var, *options, command=justify_text)
menu.pack()
text = tk.Text(root)
text.insert('1.0', "Please enter your notes here", 'justify')
text.tag_configure('justify', justify=options[0])
text.pack()
root.mainloop()
IMAGE: --->ScreenShot of the problem
IMAGE: --->How it is meant to look:
In the first hyperlink above i have attached a screenshot of the problem.
When running the windows which are connected by a button, the image on the window that is launched from the first window displays on the first window and not on the new window just opened.
At first I thought that python might be getting confused because the file name is the same. (that wasn't the case as I used a slightly different image with a different file name.
I have tried so many ways and it just doesnt work.
Directly below this line is the code for the first window:
#----Main Menu----
root_menu = Tk()
root_menu.title("Warehouse Inventory Control System")
root_menu.configure(bg = "black")
photo = PhotoImage(file="logo.gif")
photoLabel = Label(image=photo)
photoLabel.image = photo
photoLabel.grid(row=1, column=3,columnspan = 4, sticky = N)
Title_Screen = Label(root_menu,
text="Welcome to the SsangYong\n Warehouse Inventory Control System",
fg="grey",
bg="black",
font="Helevetica 25 bold",
pady = "50",
padx = "50",
).grid(row=2, column=3)
Search_Inventory = Button(root_menu,
text = "Search Inventory",
command=Search_Inventory,
fg = "Blue",
bg = "Grey",
bd = 2,
font="Helevetica 12 bold",
height = 1,
width = 50,
).grid(row=16, column=3,pady = 25,padx = 25,)
Add_Stock = Button(root_menu,
text = "Add New Items",
command = Add_To_Database,
fg = "Blue",
bg = "Grey",
bd = 2,
font="Helevetica 12 bold",
height = 1,
width = 60,
).grid(row=15, column=3,pady = 25,padx = 25,)
Print_Report = Button(root_menu,
text = "Print Stock Report",
fg = "Blue",
bg = "Grey",
bd = 2,
font="Helevetica 12 bold",
height = 1,
width = 70,
).grid(row=17, column=3,pady = 25,padx = 25,)
Help_Button = Button(root_menu,
text = "Help",
command=Help_PDF,
fg = "Red",
bg = "Black",
height = "1",
bd = "2",
font = "Helevetica 20 bold",
width = "4",
).grid(row=1, column=3,rowspan = 2, sticky= NE)
root_menu.mainloop()
and here is the code for the second window.
def Search_Inventory():
#---Search Window----
root_search = Tk()
root_search.title("Warehouse Inventory Control System")
root_search.configure(bg = "black")
#----Title displayed under the company logo on the first window----
Title_Screen = Label(root_search,
text="Warehouse Inventory Control System",
fg="grey",
bg="black",
font="Helevetica 25 bold",
pady = "50",
padx = "50",
).grid(row=3, column=4)
#----Interactive Input Boxes for the User----
#----Label to Notify what is needed in the entry box----
PN_Info_Label = Label(root_search,
text = "Part Number:",
fg="white",
bg="black",
font="Helevetica 15 bold",
padx = 50,
).grid(row=14, column=3, rowspan = 2)
#----Input Box for Part Number
PN_Display = StringVar()
Input_PartNumber = Entry(root_search,
textvariable=PN_Display,
fg = "blue",
font = "Helevtica 25 bold",
).grid(row=14, column=4)
#----A button that will proceed to the next part of the program----
Search_Button = Button(root_search,
text = "Search Inventory",
fg = "Blue",
bg = "Grey",
bd = 2,
font="Helevetica 15 bold",
command=lambda:Search_Prod(PN_Display.get()),
height = 1,
width = 15,
).grid(row=16, column=4,pady = 25,padx = 25,)
#----Information regarding how to enter the part number---
Info = Label(root_search,
text="Please Use Capitals to Enter Part Number",
fg= "red",
bg = "black",
font = "helevetica 12 bold",
).grid(row = 15, column = 4)
#----Adding the company logo to the first window----
photo = PhotoImage(file="image.gif")
photoLabel = Label(image=photo)
photoLabel.image = photo
photoLabel.grid(row=1, column=4, pady = 10)
#----Linking the Help Document----
Help_Button = Button(root_search,
text = "Help",
command=Help_PDF,
fg = "Red",
bg = "Black",
height = "1",
bd = "2",
font = "Helevetica 20 bold",
width = "4",
).grid(row=0, column=5, pady= 10,padx = 50, sticky = E)
#----Saying who the program was made by----
Credits = Label(root_search,
text = "Created By: Me",
fg = "White",
bg = "Black",
font = "Helevetica 10 underline",
).grid(row = 19, column = 5)
#To Make Sure that the window doesn't close
root_search.mainloop()
In your question you show this for your "second window":
def Search_Inventory():
#---Search Window----
root_search = Tk()
...
photoLabel = Label(image=photo)
There are two problems with the above code. For one, you're creating a second instance of Tk. You should not do this. A tkinter program should have exactly one instance of Tk. If you want additional windows you need to create instances of Toplevel.
The second problem is where you create the Label -- you are neglecting to give it a parent so it is probably defaulting to the original window. You need to change that last line to this:
photoLabel = Label(root_search, image=photo)