probalby those are two separate issues, but i can not find help for any of them
I am doing an basic interface with TKINTER that work both on PC and raspberry with LCD screen, plenty of lines to raise this. Interface is basic, just a image with some bottons on top, buttons are made with shapes (i.e. create rectangle)
issue come first that background image is only displayed briefly and the disapear, but not on debuggin mode (Visual Studio code and F5 step by step), and second, buttons do not capture click of mouse if I do not add button backgroud, if added border (as bellow example), only get hitted on the border.
codesnipet:
import tkinter as tk
...
self.canvas = tk.Canvas(self, bg=self.backgroundColor, bd=0, highlightthickness=0, relief='ridge')
self.canvas.config(cursor="circle")
self.canvas.pack(fill=tk.BOTH, expand=1)
self.canvas.bind("<Key>", event_keypress)
for i_v in range(2):
for i_h in range (5):
tagName = "pad_button_" + str(i_v * 5 + i_h)
self.canvas.tag_bind(tagName,"<Button-1>", lambda event, arg=tagName: event_callback(event, arg) )
self.canvas.create_image(10,10, image = myImg, anchor = "nw")
sleep(1)
keysize = 10
buttonsWidth = 2
colorOutline = 'red'
color = '' # <-
for i_v in range (0,2):
for i_h in range (0,5):
v_position = i_v * (keysize)
h_position = i_h * (keysize)
tagName = "pad_button_" + str(i_v * 5 + i_h)
self.canvas.create_rectangle( h_position
, v_position
, h_position + keysize
, v_position + keysize
, width=buttonsWidth
, fill=color
, outline=colorOutline
, tags=["pad_button",tagName] )
self.canvas.update()
I know I am not very good, I am learning, and I got stuck with that for several days, looking help haven't been able to come forward
I tested the "in_function_scope", does not seem to be the thing as it disvanice also in:
myImg = ...
img1=tk_canvas.create_image(4,4, image = myImg, anchor = "nw")
tk_canvas.pack()
tk_canvas.update()
time.sleep(0.3)
myImg = ...
img2=tk_canvas.create_image(40,40, image = myImg, anchor = "nw")
tk_canvas.pack()
tk_canvas.update()
(not sure what I am doing with the pack as it does not have any effect)