I created a terrain generator that can user input in, and I stumble upon a problem which is when i generate terrain and save it in (.png) when I display it in my canvas it's empty.
Here is my function that will create a map, this is outside of my class:
def get_call(result,height, width, color_range, scale, octaves, persistence, lacunarity):
height = (height.get())
width = (width.get())
color_range = (color_range.get())
scale = (scale.get())
octaves = (octaves.get())
persistence = (persistence.get())
lacunarity = (lacunarity.get())
map_data = GenerateMap(
(int(height), int(width)),
x_starting_pos=random_seed(),
y_starting_pos=random_seed(),
color_range=int(color_range),
scale= float(scale),
octaves= int(octaves),
persistance= float(persistence),
lacunarity= float(lacunarity))
Generate = map_data.generate_map("Generate")
Image.fromarray((Generate).astype('uint8')).save('result.png')
return Generate
I get the result using functools partial
. I follow this method to render the output: here:
partial(get_call, Preview_Image, Height, Width, Color_range, Scale, Octaves, Persistence, Lacunarity)
and here is the problem:
Preview_Image = tk.Canvas(top)
Preview_Image.pack()
# Display output
img = PhotoImage(file="result.png")
Preview_Image.create_image(0, 0, image=img, anchor=tk.NW)
Preview_Image.place(relx=0.017, rely=0.067, relheight=0.784
, relwidth=0.605)
I tried to use ImageTk.PhotoImage(Image.open("result.png"))
and still not displaying image in my canvas. I tried to create a new one, only the display image, works fine. Can you tell me what is the problem of this code?