from tkinter import *
from tkinter import messagebox as mb
import ind1module
class List :
pass
def add_window() :
def add() :
trn = str(en3.get())
name = en1.get()
num = en2.get()
# noinspection PyTypeChecker
trains: List[int] = list(map(int, trn.split(',')))
people.add(name, num)
add_w = Toplevel()
add_w.title('Добавить')
add_w.resizable(False, False)
add_w.geometry('225x100')
en1 = Entry(add_w)
en2 = Entry(add_w)
en3 = Entry(add_w)
lb1 = Label(add_w, text = "Название пункта назначения")
lb2 = Label(add_w, text = "Номер поезда")
lb3 = Label(add_w, text = "Время отправления")
bt1 = Button(add_w, text = "Добавить", command = add)
lb1.grid(row = 0, column = 0)
lb2.grid(row = 1, column = 0)
lb3.grid(row = 2, column = 0)
en1.grid(row = 0, column = 1)
en2.grid(row = 1, column = 1)
en3.grid(row = 2, column = 1)
bt1.grid(row = 3, column = 0, columnspan = 2)
def load_window() :
def load_f() :
people.load(en4.get())
load_w.destroy()
load_w = Toplevel()
load_w.title('Сохранение')
load_w.resizable(False, False)
load_w.geometry('225x100')
lb4 = Label(load_w, text = "Введите название файла")
en4 = Entry(load_w)
bt3 = Button(load_w, text = "Загрузить", command = load_f)
lb4.pack(padx = 2, pady = 2)
en4.pack(padx = 2, pady = 2)
bt3.pack(padx = 2, pady = 2)
def save_window() :
def save_f() :
people.save(en4.get())
save_w.destroy()
save_w = Toplevel()
save_w.title('Сохранение')
save_w.resizable(False, False)
save_w.geometry('225x100')
lb4 = Label(save_w, text = "Введите название файла")
en4 = Entry(save_w)
bt3 = Button(save_w, text = "Сохранить", command = save_f)
lb4.pack(padx = 2, pady = 2)
en4.pack(padx = 2, pady = 2)
bt3.pack(padx = 2, pady = 2)
def help_window() :
help_w = Toplevel()
help_w.title('увы,поездов на данный день не существует')
help_w.resizable(False, False)
help_w ['bg'] = 'white'
img = PhotoImage(file = 'tenor.gif')
bt2 = Button(
help_w,
image = img,
bg = 'white',
borderwidth = 0,
activebackground = 'white',
command = lambda : help_w.destroy()
)
bt2.image = img
bt2.pack()
def select_window() :
def choice() :
try :
choice_en = int(en4.get())
res = people.select(choice_en)
if res :
for idx, person in enumerate(res, 1) :
text.delete(0.0, END)
text.insert(0.0, '{:>4}: {}'.format(idx, person.name))
else :
text.delete(0.0, END)
text.insert(0.0, 'В этот день нет поездов')
except(ValueError, TypeError) :
mb.showinfo("Выбор дня",
"Введите день!")
sel_w = Toplevel()
sel_w.title('Выбрать')
sel_w.resizable(False, False)
sel_w.geometry('225x100')
lb4 = Label(sel_w, text = "Введите день")
en4 = Entry(sel_w)
bt3 = Button(sel_w, text = "Подтвердить", command = choice)
lb4.pack(padx = 2, pady = 2)
en4.pack(padx = 2, pady = 2)
bt3.pack(padx = 2, pady = 2)
def show() :
text.delete(0.0, END)
text.insert(0.0, people)
if __name__ == '__main__' :
people = ind1module.Trains()
root = Tk()
root.geometry('800x450')
root.title('Главное окно')
root.resizable(False, False)
main_menu = Menu(root)
root.config(menu = main_menu)
file_menu = Menu(main_menu, tearoff = 0)
file_menu.add_command(label = "Открыть", command = load_window)
file_menu.add_command(label = "Добавить", command = add_window)
file_menu.add_command(label = "Сохранить", command = save_window)
main_menu.add_cascade(label = "Файл", menu = file_menu)
main_menu.add_command(label = "Показать", command = show)
main_menu.add_command(label = "Выбрать", command = select_window)
main_menu.add_command(label = "Помощь", command = help_window)
main_menu.add_command(label = "Выход", command = lambda : root.destroy())
text = Text(bg = 'white', width = 97, height = 100)
text.pack(side = LEFT)
scroll = Scrollbar(command = text.yview)
scroll.pack(side = LEFT, fill = Y)
text.config(yscrollcommand = scroll.set)
root.mainloop()
каким способом можно стабилизировать данный код,при запуске и вводе при нажатии кнопку добавить выдаёт ошибку,при необходимости могу добавить код ind1module?