Python Forum
The coordinates of the Entry widget (canvas) when moving
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The coordinates of the Entry widget (canvas) when moving
#4
Hi berckut72
Here something to experiment with. Try to forget globals:
import tkinter as tk
 
root = tk.Tk()
root.geometry('600x800+10+10')
root.resizable(width=False, height=False)

def build_canvas_setup(canvas):
    xorg_txt = 30
    yorg_txt = 10
    xorg_entry = 100
    yorg_entry = 40
    ystep = 50
    
    entry_vars = list()
    
    for index in range(8):
        # Place text canvas object
        tx_slice = 'txt{}'.format(index+1)
        txtn = tx_slice*7
        canvas.create_text(xorg_txt, yorg_txt+ystep*index, text=txtn,
            anchor=tk.NW, tags='all')
            
        # Place entry widget as canvas object
        entry_var = tk.StringVar()
        entry = tk.Entry(canvas, bd = 0, justify = tk.CENTER, bg = '#7F7F7F',
            fg='white', textvariable=entry_var, width = 6)
        canvas.create_window(
            xorg_entry, yorg_entry+ystep*index, window=entry, tags='all')
        entry_vars.append(entry_var)
    
    return entry_vars    
 
def button4_event(event):
    # Linux wheel event
    print('Button-4')
    move_canvas_objects('up')
    
def button5_event(event):
    # Linux wheel event
    print('Button-5')
    move_canvas_objects('down')

def mouse_wheel_events(event):
    # Window wheel events
    if event.delta == -120:
        direction = 'down'
    elif event.delta == 120:
        direction = 'up'
    else:
        return
    move_canvas_objects(direction)
        
def move_canvas_objects(direction):
    if direction == 'up':
        canvas1.move('all', 0, -1)
    elif direction == 'down':
        canvas1.move('all', 0, 1)
    
canvas1 = tk.Canvas(root, width=600, height=750, highlightthickness=0)
canvas1.pack()
 
entry_vars = build_canvas_setup(canvas1)

for index, entry_var in enumerate(entry_vars):
    entry_value = 100 + index
    entry_var.set(entry_value)
    
# For Linux only    
canvas1.bind('<Button-4>', button4_event)
canvas1.bind('<Button-5>', button5_event)
# For Windows only
canvas1.bind('<MouseWheel>', mouse_wheel_events)

root.mainloop()
Greetings from wuf :-)
Reply


Messages In This Thread
RE: The coordinates of the Entry widget (canvas) when moving - by wuf - Jan-06-2020, 11:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 826 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,598 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,072 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  [Tkinter] canvas widget scroll issue chrisdb 2 3,921 Apr-07-2021, 05:48 AM
Last Post: chrisdb
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,307 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  Entry Widget issue PA3040 16 6,993 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] password with Entry widget TAREKYANGUI 9 6,094 Sep-24-2020, 05:27 PM
Last Post: TAREKYANGUI
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,487 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to place global tk text widget in class or on canvas puje 1 2,361 Jul-04-2020, 09:25 AM
Last Post: deanhystad
  How to retreive the grid location of an Entry widget kenwatts275 7 4,735 Apr-24-2020, 11:39 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020