Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

привет Аттон

  1. User

    привет Аттон

  2. Assistant

    Привет! Как я могу тебе помочь?

  3. User

    где у меня ошибка from tkinter import* WIDTH = 600 HEIGHT = 800

    options = ['Продолжить', 'Сохранить', 'Выйти']

    window = Tk() window.title('Меню') window.geometry(f'{WIDTH}x{HEIGHT}') canvas = Canvas(window, height=HEIGHT, width=WIDTH, )

    margin = 100 shift_y = 300 shift_x = WIDTH // 2

    elements = [] current_selected_id = 0 for i in range(len(options)): canvas.create_text(shift_x, shift_y + margin*i, text=options[i], anchor = S, font=('Comic Sans Ms', 30)) elements.append(Text)

    def update_selection(delta): global current_selected_id new_selection = current_selected_id + delta if new_selection < 0 or new_selection >= len(options): return current_selected_id += delta pass

    def update_colors(): for i in range(len(options)): if i == current_selected_id: canvas.itemconfig(elements[i], fill='red') else: canvas.itemconfig(elements[i], fill='black')

    def key_handler(event): if event.keysym == 'Up': update_selection(-1) elif event.keysym == 'Down': update_selection(1) update_colors() print(current_selected_id)

    update_colors() canvas.pack() window.bind('', key_handler) window.mainloop()

  4. Assistant

    В коде присутствует несколько ошибок:

    1. Ошибка импорта библиотеки tkinter - строка "from tkinter import*". Чтобы импортировать все имена из модуля tkinter, корректный синтаксис должен быть "from tkinter import *".

    2. Элементы списка "options" идентифицируются с помощью индексов, поэтому при создании элементов списка "elements" необходимо передать каждому элементу его соответствующий индекс, а не наименование класса "Text".

    Исправленный код:

    from tkinter import *

    WIDTH = 600 HEIGHT = 800

    options = ['Продолжить', 'Сохранить', 'Выйти']

    window = Tk() window.title('Меню') window.geometry(f'{WIDTH}x{HEIGHT}') canvas = Canvas(window, height=HEIGHT, width=WIDTH)

    margin = 100 shift_y = 300 shift_x = WIDTH // 2

    elements = [] current_selected_id = 0 for i in range(len(options)): text = options[i] element = canvas.create_text(shift_x, shift_y + margin * i, text=text, anchor=S, font=('Comic Sans Ms', 30)) elements.append(element)

    def update_selection(delta): global current_selected_id new_selection = current_selected_id + delta if new_selection < 0 or new_selection >= len(options): return

    current_selected_id += delta
    

    def update_colors(): for i in range(len(options)): if i == current_selected_id: canvas.itemconfig(elements[i], fill='red') else: canvas.itemconfig(elements[i], fill='black')

    def key_handler(event): if event.keysym == 'Up': update_selection(-1) elif event.keysym == 'Down': update_selection(1)

    update_colors()
    print(current_selected_id)
    

    update_colors() canvas.pack() window.bind('', key_handler) window.mainloop()

  5. User

    Спасибо

  6. Assistant

    Пожалуйста! Если у вас возникнут еще вопросы, не стесняйтесь задавать. Я всегда готов помочь!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.