I have several problems in my tkinter app. This is very basic there's 3 problems but I will start from the beginning.
Firstly, I want to move the widget (the first label) on all the frame (not just a small portion) because when I drag/grab it, it only moves it on it's height/width and if it's height/width is not specified it take a default one and I can only move the widget on a small portion of the frame
Secondly, I want to make the widget immuable( ie it don't automatically resize when clicked) because when I use both function (the function to drag/grab the widget and the function to display something under it when it's clicked) if I drag the element on the window and then, I click on it, it will replace the element at it's original place instead of staying on the place where it's moved with the drag function ( the element also mysteriously disapear when I click on it after the drag)
Thirdly, can use the B1-click of change() function and B1-click of make_draggable() function at the same time ? Or there's an alternative to B1-click to say 'when the mouse is pressed' not 'the mouse is clicked' (if there's a difference between click and grab). It will helps a lot.
NOTE : I can't resize the frame also, if the height and width are at 300 or 900 It will change nothing
the code :
import tkinter as tk
from tkinter import *
from tkinter import ttk
root = Tk()
frame = Frame(root,width=500,height=900)
frame.place(x=0,y=0)
label = Label(frame,text='˃LABEL',fg='green')
label.grid(column=0,row=0)
label2 = Label(frame,text='˃LABEL2',fg='green')
label3 = Label(frame,text='˃LABEL3',fg='green')
def change(event):
label['text'] = '˅LABEL'
label2.grid(column=0,row=1)
label3.grid(column=0,row=2)
if label['text'] == '˅LABEL':
label.bind('<Button-1>', hide)
def hide(event):
label['text'] = '˃LABEL'
label2.grid_forget()
label3.grid_forget()
if label['text'] == '˃LABEL':
label.bind('<Button-1>',change)
label.bind('<Button-1>',change)
def make_draggable(widget):
widget.bind("<Button-1>", on_drag_start)
widget.bind("<B1-Motion>", on_drag_motion)
def on_drag_start(event):
widget = event.widget
widget._drag_start_x = event.x
widget._drag_start_y = event.y
def on_drag_motion(event):
widget = event.widget
x = widget.winfo_x() - widget._drag_start_x + event.x
y = widget.winfo_y() - widget._drag_start_y + event.y
widget.place(x=x, y=y)
make_draggable(label)
root.mainloop()