import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() var_x = tk.IntVar() var_bug = tk.DoubleVar() var_adj = tk.DoubleVar() def _Mouse_XY(event): var_x.set(event.x) var_bug.set(round( event.widget.fraction(event.x, event.y), 3 )) #If the ttk.Scrollbar.fraction has a 1.0 output when there's 16 pixels left in the trough, #then divide those 16 pixels in the trough so that it appears longer than is. #When the fraction output is 0.0, add 0 pixels #When the fraction output is 0.5, add 8 pixels #When the fraction output is 1.0, add 16 pixels if event.widget.winfo_name() == 'ttk': adj = 16*var_bug.get() var_adj.set(round( event.widget.fraction(event.x - adj, event.y), 3 )) frame = tk.Frame(root, width=400, bg='red') frame.grid_propagate(False) frame.pack(fill='both', expand=True) frame.columnconfigure(0, weight=True) tk_scrl = tk.Scrollbar(frame, orient='horizontal', name='tk') ttk_scrl = ttk.Scrollbar(frame, orient='horizontal', name='ttk') tk_scrl.set(0, .01) ttk_scrl.set(0, .01) tk_scrl.bind("", _Mouse_XY) ttk_scrl.bind("", _Mouse_XY) container = tk.Frame(frame) container.grid(sticky='w') tk.Label(container, text="Mouse x coordinate: ", font='Courier').grid(row=0, column=0) tk.Label(container, text=".function() output: ", font='Courier').grid(row=1, column=0) tk.Label(container, text="Fixed ttk.function: ", font='Courier').grid(row=2, column=0) tk.Label(container, textvariable=var_x, font='Courier', anchor='w').grid(row=0, column=1, sticky='w') tk.Label(container, textvariable=var_bug, font='Courier', anchor='w').grid(row=1, column=1, sticky='w') tk.Label(container, textvariable=var_adj, font='Courier', anchor='w').grid(row=2, column=1, sticky='w') tk_scrl.grid(sticky='we') ttk_scrl.grid(sticky='we') frame.update_idletasks() frame.configure(height=frame.bbox('all')[3]) root.mainloop()