本文整理汇总了Python中ScrolledText.bind方法的典型用法代码示例。如果您正苦于以下问题:Python ScrolledText.bind方法的具体用法?Python ScrolledText.bind怎么用?Python ScrolledText.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScrolledText
的用法示例。
在下文中一共展示了ScrolledText.bind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LogWindow
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import bind [as 别名]
class LogWindow(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master.title("Network Simulator Log")
self.text = ScrolledText(self)
self.text.pack(fill=BOTH, expand=1)
self.pack(fill=BOTH, expand=1)
self.text.config(
background="black",
foreground="white",
font=Font(
family="Courier", weight="bold"),
# state=DISABLED,
wrap=NONE, )
self.text.tag_config("DEBUG", foreground="green")
self.text.tag_config("ERROR", foreground="red")
self.text.tag_config("CRITICAL", foreground="red")
self.text.tag_config("EXCEPTION", foreground="red")
self.text.tag_config("WARNING", foreground="yellow")
self.text.tag_config("INFO", foreground="white")
self.text.bind("<Key>", lambda e: 'break')
self.text.bind("<Return>", self._clear)
self.queue = Queue()
self._update()
def _clear(self, event):
self.text.delete(1.0, END)
return 'break'
def _update(self):
try:
while True:
text, level = self.queue.get(block=False)
at_bottom = self.text.yview()[1] == 1.0
# self.text.config(state=NORMAL)
if len(self.text.get(1.0, END).strip()) != 0:
text = "\n" + text
self.text.insert(END, text, str(level))
# self.text.config(state=DISABLED)
if at_bottom:
self.text.yview_moveto(1.0)
except Empty:
pass
self.after(50, self._update)
def append(self, entry, level="INFO"):
self.queue.put((entry, level))
示例2: __init__
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import bind [as 别名]
class SocketGUI:
def __init__(self):
"""
Sets up the tkinter window and some attributes.
"""
# Initialize Attributes
self.port = 80
self.address = "127.0.0.1"
self.connected = False
self.acting_as_server = False
self.acting_as_client = True
# Create Tkinter root window and set title
self.root = Tk()
self.root.title(PROGRAM_NAME + " " + VERSION)
self.root.protocol("WM_DELETE_WINDOW", self.close)
# Create frame
self.fpopup = Frame(self.root, width=500)
self.fpopup.pack(expand=1, fill=BOTH)
# Create the menus
self.menuobj = Menu(self.root)
self.root.config(menu=self.menuobj)
self.filemenu = Menu(self.menuobj, tearoff=0)
self.menuobj.add_cascade(label="File", menu=self.filemenu)
self.filemenu.add_command(label="Start Server", command=self.setup_server)
self.filemenu.add_command(label="Stop Server", command=self.setup_server)
self.filemenu.add_command(label="Connect", command=self.connect)
self.filemenu.add_command(label="Disconnect", command=self.disconnect)
self.filemenu.add_command(label="Exit", command=self.close)
self.editmenu = Menu(self.menuobj, tearoff=0)
self.menuobj.add_cascade(label="Edit", menu=self.editmenu)
self.editmenu.add_command(label="Configuration", command=self.configuration)
self.helpmenu = Menu(self.menuobj, tearoff=0)
self.menuobj.add_cascade(label="Help", menu=self.helpmenu)
self.helpmenu.add_command(label="About", command=self.about)
# Create the message window
self.message_window = ScrolledText(self.fpopup, width=90, height=24, background="white")
self.message_window.pack(fill=BOTH, expand=YES)
# Create the entry field
self.entry_field = Entry(self.fpopup, width=60, background="white")
self.entry_field.pack(side=LEFT, fill=BOTH, expand=YES)
# Bindings
self.entry_field.bind("<Return>", self.sendmessage_event)
self.entry_field.bind("<Control-n>", self.connect_event)
self.message_window.bind("<Control-n>", self.connect_event)
# Create Buttons
self.send_button = Button(self.fpopup, text="Send", command=self.sendmessage)
self.send_button.pack(side=LEFT, expand=NO)
# Start the Tk main routine
self.root.mainloop()
def configuration(self):
"""
Sets up the configuration menu
"""
self.configuration_menu = Toplevel()
self.configuration_menu.title(PROGRAM_NAME + " - Configuration")
self.port_label = Label(self.configuration_menu, text="Port:", width=40, anchor=W)
self.port_entry_field = Entry(self.configuration_menu, width=40, background="white")
self.address_label = Label(self.configuration_menu, text="Address:", width=40, anchor=W)
self.address_entry_field = Entry(self.configuration_menu, width=40, background="white")
self.save_configuration_button = Button(self.configuration_menu, text="Save", command=self.save_configuration)
self.cancel_configuration_button = Button(
self.configuration_menu, text="Cancel", command=self.cancel_configuration
)
self.port_entry_field.insert(END, str(self.port))
self.address_entry_field.insert(END, self.address)
self.port_label.grid(row=0, columnspan=2, sticky=W)
self.port_entry_field.grid(row=1, columnspan=2, sticky=W, pady=5)
self.address_label.grid(row=2, columnspan=2, sticky=W)
self.address_entry_field.grid(row=3, columnspan=2, sticky=W, pady=5)
self.save_configuration_button.grid(row=5, columnspan=2)
self.cancel_configuration_button.grid(row=5, column=1, columnspan=2)
def cancel_configuration(self):
"""
Destroys the configuration menu
"""
self.configuration_menu.destroy()
def cancel_server(self):
"""
Destroys the server setup menu
"""
self.server_menu.destroy()
def save_configuration(self):
"""
Saves the configuration values and closes the window
"""
#.........这里部分代码省略.........
示例3: StringVar
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import bind [as 别名]
colorschemes = {
'White': '000000.FFFFFF',
'Grey':'83406A.D1D4D1',
'Aqua': '5B8340.D1E7E0',
}
themechoice = StringVar()
themechoice.set('White')
for k in sorted(colorschemes):
themesmenu.add_radiobutton(label = k, variable = themechoice, command = theme)
bottombar = Label(textarea, text = 'Row : 1 | Column : 0')
bottombar.pack(expand = NO, fill = None, side = RIGHT, anchor = 'se')
textarea.tag_configure("active_line", background = "yellow")
textarea.bind("<Any-KeyPress>", lnupdater)
textarea.bind("<Button-1>", lnupdatermouse)
window.bind('<Control-n>', new_command)
window.bind('<Control-o>', open_command)
window.bind('<Control-s>', save_command)
window.bind('<Control-Shift-KeyPress-S>', saveas_command)
window.bind('<Control-q>', exit_command)
window.bind('<Control-z>', undo_command)
window.bind('<Control-y>', redo_command)
window.bind('<Control-x>', cut_command)
window.bind('<Control-c>', copy_command)
window.bind('<Control-v>', paste_command)
window.bind('<Control-f>', find_command)
window.bind('<Control-Shift-KeyPress-F>', findnext_command)
window.bind('<Control-Alt-KeyPress-F>', fab_command)
示例4: MemoPadFrame
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import bind [as 别名]
class MemoPadFrame( Frame ):
def __init__(self, master=None):
Frame.__init__(self, master)
# Modelの初期化
self.version = (0, 2, 5)
self.memos = MemoPad()
self.memos.addObserver(self)
# change-logger のバインド
self.changeLogger = ChangeLogger()
self.memos.addObserver( self.changeLogger )
# View-Controller の初期化
self.master.title( 'MemoPad %d.%d.%d' % self.version )
self.make_listPanel(self)
self.make_editAria(self)
self.pack(fill=BOTH)
# データの復帰
self.memos.loadImage()
def bye():
self.saveMemo() # 現在編集中のメモをセーブ
self.memos.saveImage()
print 'bye'
self.master.destroy()
self.master.protocol('WM_DELETE_WINDOW', bye )
def make_listPanel(self, parent):
frm = Frame(parent)
# リストの生成・配置
def changeTarget(evt):
try: index = int(self.memoList.curselection()[0])
except: index = None
self.saveMemo()
if index != None: self.selectMemo( index )
self.memoList = ScrolledListbox(frm,
selectmode=BROWSE,
width=72,
height=7 )
self.memoList.bind("<ButtonRelease>", changeTarget )
self.memoList.bind('<B1-Motion>', changeTarget )
self.memoList.pack(side=LEFT, fill=BOTH)
# ボタンの作成
btnfrm = Frame(frm)
def appendMemo():
self.saveMemo()
self.memos.appendMemo()
Button( btnfrm,
text='new',
command=appendMemo ).pack(side=TOP, fill=X)
def deleteMemo():
self.saveMemo()
self.memos.removeMemo()
Button( btnfrm,
text='delete',
command=deleteMemo ).pack(side=TOP, fill=X)
btnfrm.pack(side=LEFT)
frm.pack(side=TOP, fill=X)
def make_editAria(self, parent):
self.text = ScrolledText( parent )
self.text.pack(side=TOP, fill=BOTH)
def updateTitle(evt):
'''実験コード。まだ
改行や行末改行の削除に弱いです
'''
# print self.text.index('1.end')
# print self.text.index(INSERT)
if self.text.index(INSERT).split('.')[0] == '1': # 1行目
itemnum = self.memos.getSelectedIndex()
self.memoList.delete(itemnum)
self.memoList.insert(itemnum,
"%s | %s" % (self.memos[itemnum].getDatetime().strftime("%Y-%m-%d %H:%M"),
u'%s%s%s' % ( self.text.get('1.0', INSERT),
#.........这里部分代码省略.........
示例5: TextEditor
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import bind [as 别名]
#.........这里部分代码省略.........
selectmode = SINGLE)
self.commentScrollbar = Scrollbar(self.root, orient = VERTICAL)
self.commentScrollbar.config(command = self.commentBox.yview)
self.commentScrollbar.pack(side = RIGHT,fill = Y)
self.commentBoxFont = tkFont.Font(family = self.currentFont,
size = self.commentBoxFontSize)
self.commentBox.config(yscrollcommand = self.commentScrollbar.set,
background = "Grey", foreground = "Black",
font = self.commentBoxFont)
self.commentBox.pack(side = RIGHT, fill = X)
self.commentBox.insert(END,"Comments (if any) in current cursor index:")
def initMenuBar(self):
# init menuBar
self.menuBar = Menu(self.root)
# file menu option
self.addFileMenu()
# Edit menu option
self.addEditMenu()
# Find menu option
self.addFindMenu()
# View menu option
self.addViewMenu()
# Network menu
self.addNetworkMenu()
# Help menu
self.addHelpMenu()
self.root.config(menu = self.menuBar)
def onTabPressed(self, event):
if(self.fileExtension == ".py"):
self.indentationLevel += 1
def bindEvents(self):
self.textWidget.bind("<Tab>",lambda event: self.onTabPressed(event))
self.suggestionBox.bind("<Double-Button-1>",
lambda event: self.replaceWord(event))
def indent(self):
if(self.fileExtension == ".py"):
self.textWidget.insert("insert","\t"*self.indentationLevel)
def modifyIndent(self, event):
# modifies indentation based on python rules
if(self.fileExtension == ".py"):
if(event.char == ":"):
self.indentationLevel += 1
elif(event.keysym == "BackSpace"):
line = self.textWidget.get("insert linestart","insert lineend")
flag = True
for c in line:
if not((c == " ") or (c == "\t")):
flag = False
break
if(flag):
self.indentationLevel = (self.indentationLevel - 1 if
self.indentationLevel>=1 else 0)
def completeParens(self, event):
# autocomplete parens
if(event.char == "{" and self.programmingMode):
self.textWidget.insert("insert","\n"+"\t"*self.indentationLevel+"}")
self.currentText = self.textWidget.get(1.0,END)
elif(event.char == "(" and self.programmingMode):
self.textWidget.insert("insert",")")
self.currentText = self.textWidget.get(1.0,END)
示例6: __init__
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import bind [as 别名]
class Textee:
def __init__(self, master):
self.master = master
self.theme = 'dark' # the startup will always be opposite
self.options = TexteeOptions()
self.status_bar = TexteeStatusBar(master)
self.create_menu(master)
self.create_ui(master)
self.set_bindings(master)
self.file = None
self.find_text = ''
self.font_dialog = None
self.find_and_replace_dialog = None
self.windows = []
def create_menu(self, master):
self.menu = Menu(master)
master.config(menu=self.menu)
filemenu = Menu(self.menu)
self.menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=self.new_file)
filemenu.add_command(label="Open...", command=self.open_file)
filemenu.add_command(label="Save", command=self.save_file)
filemenu.add_command(label="Save As", command=lambda: self.save_file(save_as=True))
filemenu.add_separator()
filemenu.add_command(label="New window", command=self.new_window)
filemenu.add_separator()
filemenu.add_command(label="Print", command=self.printer)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=self.exit)
editmenu = Menu(self.menu)
self.menu.add_cascade(label='Edit', menu=editmenu)
editmenu.add_command(label='Copy', command=lambda: event_generate(self.editor, 'Copy'))
editmenu.add_command(label='Paste', command=lambda: event_generate(self.editor, 'Paste'))
editmenu.add_command(label='Undo', command=lambda: event_generate(self.editor, 'Undo'))
editmenu.add_separator()
editmenu.add_command(label='Goto', command=self.goto_line) # need to develop custom find with regex
editmenu.add_command(label='Find', command=self.find) # need to develop custom find with regex
editmenu.add_command(label='Find & Replace', command=self.find_and_replace) # need to test the replace logic in separate playground
editmenu.add_separator()
editmenu.add_command(label='Check spelling', command=self.spell_check) # need to see how to use system's grammer check.. if not possible remove it.
formatmenu = Menu(self.menu)
self.menu.add_cascade(label='Format', menu=formatmenu)
formatmenu.add_command(label='Font', command=self.select_font) # pop-up to select system fonts
formatmenu.add_checkbutton(label='Wrap', onvalue=True, offvalue=False, variable=self.options.wrap, command=self.toggle_wrap)
viewmenu = Menu(self.menu)
self.menu.add_cascade(label='View', menu=viewmenu)
viewmenu.add_checkbutton(label='Status bar', onvalue=True, offvalue=False, variable=self.options.status_bar, command=lambda: self.status_bar.display(self.options.status_bar.get()))
viewmenu.add_command(label='Toggle theme', command=self.toggle_theme)
helpmenu = Menu(self.menu)
self.menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About", command=lambda : self.about())
def create_ui(self, master):
self.editor = ScrolledText(master, width=100, height=50, highlightthickness=0)
self.editor.config(undo=True)
self.editor.pack(expand=YES, fill='both', padx=0, pady=0)
self.toggle_theme()
#print_configs(self.editor)
# Create pop-menu for the entire editor.. do some cool stuff with it
self.editor.popmenu = Menu(self.master, tearoff=0)
# TODO : later need to do smart copy/paste i.e. selected text copy of entire line copy
self.editor.popmenu.add_command(label='Copy', command=lambda: event_generate(self.editor, 'Copy'))
self.editor.popmenu.add_command(label='Paste', command=lambda: event_generate(self.editor, 'Paste'))
# TODO : disable undo when not available, not sure if its possible. Need to check research later
self.editor.popmenu.add_command(label='Undo', command=lambda: event_generate(self.editor, 'Undo'))
self.editor.popmenu.add_separator()
# TODO : 'share' this will be the best feature in the editor, share the file with the future textee sharing api
self.editor.popmenu.add_command(label='Share', command=do_nothing)
# add status bar by default, it can be hidden from menu
self.status_bar.update_status('Hi there')
def set_bindings(self, master):
master.bind_class('Text', '<Control-a>', select_all)
master.bind_class('Text', '<Control-s>', lambda event: self.save_file())
master.bind_class('Text', '<Control-o>', lambda event: self.open_file())
master.bind_class('Text', '<Control-n>', lambda event: self.new_file())
master.bind_class('Text', '<Control-g>', lambda event: self.goto_line())
master.bind_class('Text', '<Control-f>', lambda event: self.find())
master.bind_class('Text', '<Control-p>', lambda event: self.printer())
master.bind_class('Text', '<Control-;>', lambda event: self.find_and_replace()) # this function is only for temporoy use - for dev purpose only
# editor section bindings only
self.editor.bind('<Button-2>', self.show_right_click_menu) # for right-click
self.editor.bind('<Button-3>', self.show_right_click_menu) # for middle-click (scroll press)
#display the current cursor position
self.display_current_position()
def new_file(self):
self.file = None
self.editor.delete('1.0', END+'-1c') # clear all the contents
#.........这里部分代码省略.........