Python Forum
Tkinter widgets not appearing (3.x)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter widgets not appearing (3.x)
#1
Hi, my code doesn't seem to fully work. The self.ram_current_label and self.ram_maximum_label aren't being displayed. Everything in MapGUI works, along with the self.test_label, and removing MapGUI doesn't fix the issue either. I'm not the sharpest, so there might be a glaring mistake! I'm not receiving any error messages. I've added the entire code because I'm really not sure what's causing this. Thanks.

"""
NeuralCrack Main GUI

To be imported into the base engine
"""

from tkinter import *
import os
# Gets the base neuralcrack path and the resources path

path_base = os.getcwd().replace("\\engines", "\\")
path_resources = path_base + "resources\\"


class MapGUI:
   def __init__(self, master):

       # The map
       def map_resize_inc():
           map_image = PhotoImage(file=map_path).zoom(1, 1)
           self.map_button.config(image=map_image, command=map_resize_dec)
           self.map_button.map_image = map_image
           self.map_button.update()

       def map_resize_dec():
           map_image = PhotoImage(file=map_path).subsample(3, 3)
           self.map_button.config(image=map_image, command=map_resize_inc)
           self.map_button.map_image = map_image
           self.map_button.update()

       map_path = path_resources + "map_temp.png"
       map_image = PhotoImage(file=map_path).subsample(3, 3)
       self.map_button = Button(master, image=map_image, command=map_resize_inc)
       self.map_button.map_image = map_image
       self.map_button.grid(row=1,column=1)



class RAMCounterGUI:
   def __init__(self, master):

       # The RAM Bar
       self.ram_maximum = 3200
       self.ram_current = 100

       self.ram_maximum_label = Label(master, text="a", borderwidth=1, highlightcolor="black", width=self.ram_maximum,
                                      height=20)
       self.ram_current_label = Label(master, fg="red", width=self.ram_current, height=10)

       self.test_label = Label(master, text="Test")
       self.test_label.grid()
       self.ram_maximum_label.grid(column=2)
       self.ram_current_label.grid(column=2)


root = Tk()
root.geometry("1920x1080")
map_gui_initialize = MapGUI(root)
ram_gui_initialize = RAMCounterGUI(root)
root.mainloop()
Reply
#2
(Jul-05-2017, 08:48 PM)RSAngryfiend Wrote: The self.ram_current_label and self.ram_maximum_label aren't being displayed
Well... they are being displayed. There's just nothing to display, so they blend into the background. If you give the labels a background color (bg), then you'll see them.

Try this:
        self.ram_maximum_label = Label(master, bg="green", width=100)
        self.ram_current_label = Label(master, bg="red", width=10)
        self.ram_maximum_label.grid(column=2, row=3)
        self.ram_current_label.grid(column=2, row=3)
The next problem you'll have, is that the width of a label is unrelated to how many pixels wide it is. So having the max label 3200 "units" wide will make it wider than the window, and since the current label is in the same cell of the grid and is center aligned, it's just completely off screen. You could fix that by anchoring it to the left (I think tk calls that "sticky"), but probably the better way would be to scale the numbers down.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 571 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  make widgets disappear from tkinter jacksfrustration 12 1,121 Feb-06-2024, 03:58 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 4,234 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  .get() from generated Entry widgets in tkinter snakes 4 4,218 May-03-2021, 11:26 PM
Last Post: snakes
  Using Tkinter widgets on child window chewy1418 8 7,215 Feb-27-2020, 10:34 PM
Last Post: Marbelous
  Buttons not appearing, first time button making admiral_hawk 5 3,390 Dec-31-2018, 03:26 AM
Last Post: admiral_hawk
  Tkinter widgets not fully loading nortski 3 3,528 Apr-02-2018, 12:23 PM
Last Post: nortski
  [Tkinter] Tkinter widgets driving Arduino uno output pins woodcncwnc 3 4,554 Jan-29-2018, 08:21 PM
Last Post: woodcncwnc

Forum Jump:

User Panel Messages

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