@Jeronymo32

Как сделать так, чтобы созданные функцией кнопки выполняли одну функцию, но каждая отдельно?

Мне нужно, чтобы кнопки созданные функций перемещались, но получается, что новая перемещается вместо старой, та больше не используется. Вот код:
import tkinter as tk 
root = tk.Tk()
root.state('zoomed')
root.resizable(0,0)
def on_mouse_down(event):
    global dif_x, dif_y
    win_position = [int(coord) for coord in root.wm_geometry().split('+')[1:]]
    dif_x, dif_y = win_position[0] - event.x, win_position[1] - event.y
  
  
def update_position(event):
    button.place(x=(event.x_root + dif_x), y=(event.y_root + dif_y-26))
    print((event.x_root + dif_x, event.y_root + dif_y))
  
def on_mouse_down1(event):
    global dif_x, dif_y
    win_position = [int(coord) for coord in root.wm_geometry().split('+')[1:]]
    dif_x, dif_y = win_position[0] - event.x, win_position[1] - event.y
  
  
def update_position1(event):
    scrollbar.place(x=(event.x_root + dif_x), y=(event.y_root + dif_y-26))
    print((event.x_root + dif_x, event.y_root + dif_y))
B1=tk.Button(root)
button_identities = [B1]
bn=[]
def search():
    global bname, bnr
    
    if button_identities.index(xl):
        
        p=button_identities.index(xl)
        bname = (button_identities[p])
        print(p)
        bname.bind('<ButtonPress-1>', on_mouse_down)
        bname.bind('<B1-Motion>', update_position2)
        
    
    else:
        p=0
    
    bn.append(p)
    print(bn)
def click():
    global xl, bname
    
    xl=tk.Button(root, command=search)
    xl.pack()
    
    button_identities.append(xl)
    
    print(button_identities)

       
        
def update_position2(event):
    bname.place(x=(event.x_root + dif_x), y=(event.y_root + dif_y-26))
    bnr.place(x=(event.x_root + dif_x), y=(event.y_root + dif_y-26))
    

    
    
buttons = tk.Button(root, command=click)
buttons.pack()



button=tk.Button(root)
scrollbar=tk.Scrollbar(root)
button.pack()
scrollbar.pack()
button.bind('<ButtonPress-1>', on_mouse_down)
button.bind('<B1-Motion>', update_position)
  
scrollbar.bind('<ButtonPress-1>', on_mouse_down1)
scrollbar.bind('<B1-Motion>', update_position1)
  
  
root.mainloop()
  • Вопрос задан
  • 73 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы