не меняется изображение. Python tkinter
import sqlite3
from tkinter import *
from PIL import Image, ImageTk
import requests
from io import BytesIO
class Trucking:
def __init__(self, request_id):
self.id = ...
self.tip_perevozki_gruzov = ...
self.tehnika = ...
self.info_o_voditele = ...
self.svyaz_s_voditelem = ...
self.formirovanie_dannih = ...
self.update_data(request_id)
def update_data(self, request_id):
self.id = get_table_one_data("id", TABLES["tc"], f"id = {request_id}")
self.tip_perevozki_gruzov = get_table_one_data("tip_perevozki_gruzov",
TABLES["tc"], f"id = {request_id}")
self.tehnika = get_table_one_data("tehnika", TABLES["tc"], f"id = {request_id}")
self.info_o_voditele = get_table_one_data("info_o_voditele",
TABLES["tc"], f"id = {request_id}")
self.svyaz_s_voditelem = get_table_one_data("svyaz_s_voditelem",
TABLES["tc"], f"id = {request_id}")
self.formirovanie_dannih = get_table_one_data("formirovanie_dannih",
TABLES["tc"], f"id = {request_id}")
def print_data(self):
print(self.id)
print(self.tip_perevozki_gruzov)
print(self.tehnika)
print(self.info_o_voditele)
print(self.svyaz_s_voditelem)
print(self.formirovanie_dannih)
def execute(request):
cur.execute(request)
con.commit()
def get_table_one_data(data, table, condition):
global is_scroll
try:
is_scroll = False
cur.execute(f"SELECT {data} FROM {table} WHERE {condition}")
return cur.fetchone()[0]
except Exception as e:
is_scroll = True
print(e)
def change_widgets_text():
label_id["text"] = trucking.id
label_tip_perevozki_gruzov["text"] = trucking.tip_perevozki_gruzov
label_tehnika["text"] = trucking.tehnika
label_info_o_voditele["text"] = trucking.info_o_voditele
label_svyaz_s_voditelem["text"] = trucking.svyaz_s_voditelem
label_formirovanie_dannih["text"] = trucking.formirovanie_dannih
def get_all_table_id():
execute(f"SELECT id FROM {TABLES['tc']}")
r = cur.fetchall()
_all_id = []
for _id_arr in r:
_all_id.append(_id_arr[0])
return _all_id
def edit_id_and_data(side):
global id_counter
if side == "prev" and id_counter > 0:
id_counter -= 1
if side == "next" and id_counter < len(all_id) - 1:
id_counter += 1
trucking.update_data(all_id[id_counter])
change_widgets_text()
con = sqlite3.connect("perevozki_gruzov.db")
cur = con.cursor()
# константы
LABEL_COLOR = "#BBB"
BUTTON_COLOR = "#AAA"
TABLES = {"tc": "companii_gruzoperevozok"}
#
all_id = get_all_table_id()
id_counter = 0
is_scroll = False
#
trucking = Trucking(all_id[id_counter])
# инициация приложения
root = Tk()
root.title("Грузоперевозки")
root.geometry("800x650")
root.resizable(width=False, height=False)
# создание виджетов
label_id_mark = Label(text="ID", background=LABEL_COLOR,
relief="solid", borderwidth=1)
label_tip_perevozki_gruzov_mark = Label(text="Тип перевозки",
background=LABEL_COLOR, relief="solid", borderwidth=1)
label_tehnika_mark = Label(text="Техника", background=LABEL_COLOR,
relief="solid", borderwidth=1)
label_info_o_voditele_mark = Label(text="Инфо о водителе",
background=LABEL_COLOR, relief="solid", borderwidth=1)
label_svyaz_s_voditelem_mark = Label(text="Связь с водителем",
background=LABEL_COLOR, relief="solid", borderwidth=1)
label_formirovanie_dannih_mark = Label(text="Формирование данных",
background=LABEL_COLOR, relief="solid", borderwidth=1)
label_id = Label(text=trucking.id, background=LABEL_COLOR,
relief="solid", borderwidth=1)
label_tip_perevozki_gruzov = Label(text=trucking.tip_perevozki_gruzov,
background=LABEL_COLOR, relief="solid", borderwidth=1)
label_tehnika = Label(text=trucking.tehnika, background=LABEL_COLOR,
relief="solid", borderwidth=1)
label_info_o_voditele = Label(text=trucking.info_o_voditele,
background=LABEL_COLOR, relief="solid", borderwidth=1)
label_svyaz_s_voditelem = Label(text=trucking.svyaz_s_voditelem,
background=LABEL_COLOR, relief="solid", borderwidth=1)
label_formirovanie_dannih = Label(text=trucking.formirovanie_dannih,
background=LABEL_COLOR, relief="solid", borderwidth=1)
def prev_event():
edit_id_and_data("prev")
#print(req_id)
def next_event():
edit_id_and_data("next")
#print(req_id)
button_prev = Button(text="Назад", background=BUTTON_COLOR,
command=prev_event)
button_next = Button(text="Вперед", background=BUTTON_COLOR,
command=next_event)
# позиционирование виджетов
label_id_mark.place(width=50, height=30, anchor="e", x=55, y=20)
label_tip_perevozki_gruzov_mark.place(width=125, height=30, anchor="w",
x=60, y=20)
label_tehnika_mark.place(width=125, height=30, anchor="w", x=190, y=20)
label_info_o_voditele_mark.place(width=125, height=30, anchor="w", x=320,
y=20)
label_svyaz_s_voditelem_mark.place(width=115, height=30, anchor="w",
x=450, y=20)
label_formirovanie_dannih_mark.place(width=225, height=30, anchor="w",
x=570, y=20)
label_id.place(width=50, height=30, anchor="e", x=55, y=55)
label_tip_perevozki_gruzov.place(width=125, height=30, anchor="w", x=60,
y=55)
label_tehnika.place(width=125, height=30, anchor="w", x=190, y=55)
label_info_o_voditele.place(width=125, height=30, anchor="w", x=320, y=55)
label_svyaz_s_voditelem.place(width=115, height=30, anchor="w", x=450,
y=55)
label_formirovanie_dannih.place(width=225, height=30, anchor="w", x=570,
y=55)
button_prev.place(width=75, height=25, x=5, y=550)
button_next.place(width=75, height=25, x=85, y=550)
# Изображение
canv = Canvas(root, width=700, height=450, bg='white')
canv.place(x=800 / 2 - int(canv["width"]) / 2, y=75)
url1 = "https://img.freepik.com/free-photo/image-of-realistic-blank-truck-on-white-background_125540-4543.jpg?w=900&t=st=1708329320~exp=1708329920~hmac=695948b3e1260b76b22227fddb9220c0815257ad61dbe014946168c9b3dba926"
response1 = requests.get(url1)
img1 = ImageTk.PhotoImage(Image.open(BytesIO(response1.content)))
url2 = "https://img.freepik.com/free-photo/night-trucking-delivers-cargo-to-steel-warehouse-generated-by-ai_188544-17396.jpg?w=1060&t=st=1708329344~exp=1708329944~hmac=9f3427f991acfb79ac8f4ade16346db616866e24070aa0f9d90e9e62499b90e3"
response2 = requests.get(url2)
img2 = ImageTk.PhotoImage(Image.open(BytesIO(response2.content)))
url3 = "https://img.freepik.com/free-photo/truck-long-vehicle-ready-for-delivering-and-transport_342744-1294.jpg?w=900&t=st=1708329480~exp=1708330080~hmac=333705de9adabbb17f1d112c549fd076dde1f36688288324e1485aa46fc35323"
response3 = requests.get(url3)
img3 = ImageTk.PhotoImage(Image.open(BytesIO(response3.content)))
url4 = "https://img.freepik.com/free-photo/exposure-of-an-orange-american-truck-on-a-black-background-ai-generative_123827-24990.jpg?w=900&t=st=1708329544~exp=1708330144~hmac=b4d220eaf314dbbd4bbc6a75a7bce480234d6b95a6cfb6dfcddb8a4201f6d9f7"
response4 = requests.get(url4)
img4 = ImageTk.PhotoImage(Image.open(BytesIO(response4.content)))
current_image = img1
canv.create_image(0, 0, anchor=NW, image=current_image)
def update_image():
global current_image
if all_id[id_counter] == 1:
current_image = img1
elif all_id[id_counter] == 2:
current_image = img2
elif all_id[id_counter] == 3:
current_image = img3
elif all_id[id_counter] == 4:
current_image = img4
canv.delete("all")
canv.create_image(0, 0, anchor=NW, image=current_image)
canv.update()
root.mainloop()
вот сам код, у приятеля работает прекрасно, а у меня на всех страницах отображается изображения из-под img1. не знаю что не так...
данные в таблицу заполняются через базу данных(SQlite). кроме фото