added relative path
This commit is contained in:
parent
b934c0f3bd
commit
de0e396328
21
main.py
21
main.py
@ -1,9 +1,9 @@
|
||||
from ctypes import alignment
|
||||
from tkinter import *
|
||||
from tkinter import ttk, filedialog, messagebox
|
||||
import configparser
|
||||
import db
|
||||
from PIL import ImageTk, Image
|
||||
import os
|
||||
|
||||
root = None
|
||||
database = None
|
||||
@ -77,8 +77,9 @@ def add_record_window(event=""):
|
||||
|
||||
def browse_image():
|
||||
filename = filedialog.askopenfilename(parent=add_window)
|
||||
path = relative_path(filename)
|
||||
image_path_entry.delete(0, "end")
|
||||
image_path_entry.insert(0, filename)
|
||||
image_path_entry.insert(0, path)
|
||||
|
||||
def add_button():
|
||||
database.add_record(name=name_entry.get(), description=description_entry.get(
|
||||
@ -119,8 +120,9 @@ def update_record_window(event=""):
|
||||
|
||||
def browse_image():
|
||||
filename = filedialog.askopenfilename(parent=update_window)
|
||||
path = relative_path(filename)
|
||||
image_path_entry.delete(0, "end")
|
||||
image_path_entry.insert(0, filename)
|
||||
image_path_entry.insert(0, path)
|
||||
|
||||
def edit_button():
|
||||
database.edit_record(selected, name=name_entry.get(), description=description_entry.get(
|
||||
@ -224,6 +226,19 @@ def confirm_delete():
|
||||
messagebox.showinfo("Отмена", "Удаление отменено")
|
||||
|
||||
|
||||
def relative_path(path):
|
||||
# Получение пути к текущему файлу
|
||||
current_file_path = os.path.abspath(__file__)
|
||||
|
||||
# Получение пути к текущему рабочему каталогу
|
||||
current_directory = os.path.dirname(current_file_path)
|
||||
|
||||
# Получение относительного пути к файлу
|
||||
relative_path = os.path.relpath(path, current_directory)
|
||||
|
||||
return relative_path
|
||||
|
||||
|
||||
def main():
|
||||
global root, listbox, database, image_label, desc_label
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user