【发布时间】:2015-07-03 00:37:28
【问题描述】:
我试图在按下按钮时将 Entry 小部件的光标向左移动。通过我的尝试,我可以获得光标的当前位置,但我无法移动它。
我在网上搜索,但没有找到任何有用的东西。如何在 Entry 小部件中移动光标位置?
#! /usr/bin/python
from Tkinter import *
class App(Frame):
def __init__(self,parent):
Frame.__init__(self,parent)
self.parent=parent
self.button = Button(self.parent, text="Shift_cursor_left", fg="red")
self.button.pack(side=LEFT)
self.entry_label=Entry(self.parent,width=10,bd="1",bg="cyan",font=("Helvetica",15),text="python",justify=RIGHT)
self.entry_label.pack()
self.entry_label.focus()
self.entry_label.insert(0,"Python")
self.button["command"]=self.shift_cursor()
def shift_cursor(self):
position = self.entry_label.index(INSERT)
print position
# self.entry_label.mark_set(INSERT,'1.2')
root=Tk()
app=App(root)
root.mainloop()
【问题讨论】:
标签: python python-2.7 tkinter