0

I work with Python (PyCharm as IDE) and tkinter and I'm trying to create a four in a row game. As such I'm struggling to visualise the build-up of the empty fields.

I have the following Code:

Main:

 def generate_field(mainframe):

    empty_cell = PhotoImage\
    ("C:\\... Pseudopath which works")
    column = 7
    row = 6
    cell = [None] * column * row
    c = 0

    for x in range (0, 7):
        for y in range (0, 6):
            cell[c] = Field(x,y, empty_cell)
            pen = Label(mainframe, image = cell[c].Graphic)
            pen.pack(side="right")
            c = c + 1


    mainframe.mainloop()

Field:

class Field:

def __init__(self, x, y, graphic):
    self.Value = 0   #0 = empty, 1 = red, 2 = yellow
    self.Graphic = graphic
    self.X = x
    self.Y = y

The code compiles properly but for no apparent reason it doesn't want to pack the PhotoImages (path is 100% valid) Tkinter shows just the empty window, without my graphics of an empty cell.

It worked once, but after I changed my code to a less hard-coded structure, out of mystery all my attempts to reproduce my earlier results are destined to fail.

Klunky
  • 15
  • 4
  • 1
    I think that the images are garbage-collected like in http://stackoverflow.com/questions/27430648/python-tkinter-2-7-issue-with-image. – j_4321 May 11 '17 at 12:25
  • What is your evidence that the images "don't pack"? Could it be that they are "packed" just fine, but that the images simply aren't appearing? For example, if you gave each label a visible border, do you see the border? – Bryan Oakley May 11 '17 at 13:56

0 Answers0