I`m using Python with PIL
Short Version:
I want to display an Image in the background (which only works with Label
s to my knowledge?)
Every widget has this Label
now as master
.
I also want to add widgets later (with said Label
as master) with a binded function.
When I click on the Button
, every widget except the newly created one disappears
(simple Code below).
Question:
Are there commands to prevent this,
or are there alternatives to Label
s I can use,
or is there a post already addressing this problem?
Long Version:
I'm programming Monopoly in Python. My design includes a Frame that is shared from two widgets. With a Button
you can switch between those widgets.
To make the design comfortable and more visual appealing, one of those widget (a Label
) has the background of a wood table. When creating, everything is placed as it should be, but when I press a Button
to add a widget into my 2 dimensional Frame
Matrix
(on the Label
widget), everything on the Label
but the new created widget disappears.
When forgetting the Label
calling it again, everything is as it should (with new widget)
Because of the many things I already added to this Label
, reloading the Label
won't be an option, the delay would be to significant.
I have encountered this problem twice before but always managed to go around it somehow.
While experiencing this problem now 3 times, I could never find any solution to this problem on my own or in the Internet...and trust me I searched (or searched with the wrong keywords, I don't know.)
If my goal isn't clear yet:
I want to add widgets to a Label
(or other widgets that support images), whenever I want (events) without every other child (widgets) of this Label
to disappear.
The code below is a very simple code to show you an example for my problem. My actual code for my program has over 2K lines and my coding is not something that is easy to look at, so I won't include it.
from tkinter import*
import tkinter as tk
class Oberflaeche:
def __init__(self, main):
self.mainframe = Label(main,height= 1000,width = 1000, bg='azure4' )
self.mainframe.pack()
self.array1 = []
# To resemble it (for me):
for k in range(5):
array2 = []
self.array1.append(array2)
for i in range(11):
array2.append(Frame(self.mainframe, height=120, width=80, bg='red'))
self.array1[k][i].grid(row=k, column=i, pady=(5, 5), padx=(1, 1))
# Just for visual purpose:
for n in range(3):
aLabel = Label(master=self.array1[n][n],bg = 'blue')
aLabel.pack()
aLabel.bind('<Button-1>', self.show)
# Something I want to add:
def show(self,event):
Label1 = Label(self.array1[2][3], bg = 'yellow')
Label1.pack()
main = tk.Tk()
Oberflaeche = Oberflaeche(main)
main.mainloop()