Списки tkinter с изменяемыми размерами столбцов - фатальная ошибка рекурсии - PullRequest
0 голосов
/ 10 ноября 2018

Я использую метод .place. Следующий код является рабочим упрощением столбцов с изменяемым размером и сообщением об ошибке, которое появляется при перемещении столбцов мышью через короткое время.

import tkinter as tk


def column_drag(event):
    #print(event.x)
    for ii, i in enumerate(column_head):
        if ii != 0:
            currCur = root.winfo_pointerx() - root.winfo_rootx()
            if currCur <= column_head[ii].winfo_x() + 10 and currCur >= column_head[ii].winfo_x() - 10:
                if currCur <= column_head[ii].winfo_x() + 10 and currCur >= column_head[ii].winfo_x() - 10:
                    column_head[ii].configure(cursor="sb_h_double_arrow")
                    column_posx[ii] = currCur
                    column_user[ii] = True
                refresh_run_display()
            else: column_head[ii].configure(cursor="arrow")

def resize(event):
    refresh_run_display()


def refresh_run_display():
    ii = len(column_body)-1
    for i in reversed(column_body):
        # Last column
        if ii+1 == len(column_body):
            if column_user[ii] is False:
                column_head[ii].place(x=ii * 150, y=0, height=20, width=root.winfo_width())
                column_head[ii].update()
                column_body[ii].place(x=ii * 150, y=column_head[ii].winfo_height(), height=120, width=root.winfo_width())
            if column_user[ii] is True:
                column_head[ii].place(x=column_posx[ii], y=0, height=20, width=root.winfo_width())
                column_head[ii].update()
                column_body[ii].place(x=column_posx[ii], y=column_head[ii].winfo_height(), height=120, width=root.winfo_width())
        #middle column
        if ii+1 != len(column_body) and ii != 0:
            if column_user[ii] is False:
                column_head[ii].place(x=ii * 150, y=0, height=20, width=column_head[ii+1].winfo_x())
                column_head[ii].update()
                column_body[ii].place(x=ii * 150, y=column_head[ii].winfo_height(), height=120, width=column_head[ii+1].winfo_x())
            if column_user[ii] is True:
                column_head[ii].place(x=column_posx[ii], y=0, height=20, width=column_head[ii+1].winfo_x())
                column_head[ii].update()
                column_body[ii].place(x=column_posx[ii], y=column_head[ii].winfo_height(), height=120, width=column_head[ii+1].winfo_x())
        #first column
        if ii == 0:
            if column_user[ii] is False:
                column_head[ii].place(x=1, y=0, height=20, width=column_head[ii+1].winfo_x())
                column_head[ii].update()
                column_body[ii].place(x=1, y=column_head[ii].winfo_height(), height=120, width=column_head[ii+1].winfo_x())
            if column_user[ii] is True:
                column_head[ii].place(x=1, y=0, height=20, width=column_head[ii+1].winfo_x())
                column_head[ii].update()
                column_body[ii].place(x=1, y=column_head[ii].winfo_height(), height=120, width=column_head[ii+1].winfo_x())
        ii = ii - 1



root = tk.Tk()
gui_w = 650
gui_h = 270
gui_h_old = 0
x = (root.winfo_screenwidth()/2) - (gui_w/2)
y = (root.winfo_screenheight()/2) - (gui_h/2)
root.geometry('%dx%d+%d+%d' % (gui_w, gui_h, x, y))
root.bind('<Configure>', resize)
root.minsize(width=350, height=315)
root.maxsize(width=root.winfo_screenwidth(), height=root.winfo_screenheight())


column_names = ['id', 'name', 'size', 'time']
column_body = [tk.Listbox(borderwidth=0, highlightthickness=0, exportselection=0, activestyle='none') for i in column_names]
column_head = [tk.Button(text=i, borderwidth=0.5, relief="ridge", anchor="w") for i in column_names]
[i.bind("<Motion>", column_drag) for i in column_head]

column_lead = [False for i in column_names]; column_lead[0] = True
column_flip = [False for i in column_names]
column_user = [False for i in column_names]
column_posx = [0 for i in column_names]

root.mainloop()

Сообщение об ошибке:

Fatal Python error: Cannot recover from stack overflow.

Current thread 0x00001440 (most recent call first):
  File "C:\python37\lib\tkinter\__init__.py", line 1704 in __call__
  File "C:\python37\lib\tkinter\__init__.py", line 1177 in update
  File "path.../tst.py", line 42 in refresh_run_display
  File "path.../tst.py", line 14 in column_drag
Process finished with exit code -1073740791 (0xC0000409)

Я бы хотел сохранить текущий формат, если это возможно. Пожалуйста, помогите!

1 Ответ

0 голосов
/ 11 ноября 2018

Я думаю, что column_head[ii].update() вызывает эту ошибку.

Раньше, при тестировании column_head[ii].winfo_height() вернуло бы неверное значение, когда его попросили вернуть его значение в следующей строке: column_head[ii].place(x=ii * 150, y=0, height=20, width=root.winfo_width())

column_head[ii].update() решил это, но теперь, видимо, в этом нет необходимости, и комментирование всего column_head[ii].update(), похоже, сработало. Это была строка, вызванная в отладке

...