SchwarzbrotMitHummus
SchwarzbrotMitHummus

Reputation: 69

Tkinter Entry justify text right when text is larger than the box

I have some tk.Entry()s in my gui. The text inside the entries is always right-aligned. But once the text is larger than the box, the text is left-aligned.

Sample-Code:

import tkinter as tk
root = tk.Tk()

small_text = "abc"
big_text = "abcdefghijklmnopqrstuvwxyz"
small_entry = tk.Entry(root, width=10, justify="right")
big_entry = tk.Entry(root, width=10, justify="right")
small_entry.insert(0, small_text)
big_entry.insert(0, big_text)
small_entry.pack()
big_entry.pack()

# what i want to see for big_entry:
wanna_see_text = "qrstuvwxyz"
wanna_see_entry = tk.Entry(root, width=10, justify="right")
wanna_see_entry.insert(0, wanna_see_text)
wanna_see_entry.pack()
root.mainloop()

The result:

enter image description here

The first box is perfect. Second box contains whole alphabet but it's left-aligned. I want that the second box looks like the third box even if it contains the entire alphabet,

Thanks for your help :)

Upvotes: 2

Views: 5041

Answers (1)

Phoenixo
Phoenixo

Reputation: 2113

You can use big_entry.xview_moveto(1)

xview_moveto() requires a fraction between 0 and 1 (documentation here)

Result :

result

Upvotes: 5

Related Questions