如何将光标放在文本框tkinter的左侧?

时间:2017-10-19 12:05:30

标签: python tkinter

我通过tkinter在python 3.6.2中编写了下面的代码,我希望当单击它时光标位于文本框的右侧。

from tkinter import *
class Application(Frame):
    def __init__(self,master):
        super(Application, self).__init__(master)
        self.grid()
        self.create_main()
    def create_main(self):
        print("testing")
        self.title = Label(self, text=" Stuck In The Circle ")
        self.title.grid(row=0, column=2)
        self.user_entry_label = Label(self, text="Username: ")
        self.user_entry_label.grid(row=1, column=1)
        self.user_entry = Entry(self)                        
        self.user_entry.grid(row=1, column=2)
        self.pass_entry_label = Label(self, text="Password: ")
        self.pass_entry_label.grid(row=2, column=1)
        self.pass_entry = Entry(self)                        
        self.pass_entry.grid(row=2, column=2)
        self.sign_in_butt = Button(self, text="Sign In",command = self.logging_in)#SIGN IN BUTTON
        self.sign_in_butt.grid(row=5, column=2)
    def logging_in(self):
     user_get = self.user_entry.get()
     pass_get = self.pass_entry.get()
root = Tk()
root.title("Stuck in the Circle")
root.geometry("400x100")
app = Application(root)
root.mainloop()

如何解决?

1 个答案:

答案 0 :(得分:0)

您可以使用justify选项让文字右对齐:

self.user_entry = Entry(self, justify="right")   
self.pass_entry = Entry(self, justify="right")

我不确定这是否正是您正在寻找的,但它是唯一可用的选项。如果要将字符添加到左侧,可以使用自定义绑定完成。