python tkinter insert函数_Python tkinter.INSERT属性代码示例

本文详细介绍了Python tkinter库中INSERT属性的使用方法,包括加载文件、搜索、选择全部、导入脚本等场景的代码示例。通过17个精选示例,帮助开发者更好地理解和应用tkinter.INSERT。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文整理汇总了Python中tkinter.INSERT属性的典型用法代码示例。如果您正苦于以下问题:Python tkinter.INSERT属性的具体用法?Python tkinter.INSERT怎么用?Python tkinter.INSERT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在模块tkinter的用法示例。

在下文中一共展示了tkinter.INSERT属性的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: load

​点赞 6

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def load(self, filename):

self.delete("1.0", tk.END)

try:

with open(filename, "r", encoding="utf-8") as file:

self.insert("1.0", file.read())

except EnvironmentError as err:

self.set_status_text("Failed to load {}".format(filename))

return False

self.mark_set(tk.INSERT, "1.0")

self.edit_modified(False)

self.edit_reset()

self.master.title("{} \u2014 {}".format(os.path.basename(filename),

APPNAME))

self.filename = filename

self.set_status_text("Loaded {}".format(filename))

return True

开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:18,

示例2: find

​点赞 6

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def find(self, event=None):

text = self.findEntry.get()

assert text

length = len(text)

caseInsensitive = not self.caseSensitive.get()

wholeWords = self.wholeWords.get()

if wholeWords:

text = r"\m{}\M".format(re.escape(text)) # Tcl regex syntax

self.editor.tag_remove(FIND_TAG, "1.0", tk.END)

insert = self.editor.index(tk.INSERT)

start = self.editor.search(text, insert, nocase=caseInsensitive,

regexp=wholeWords)

if start and start == insert:

start = self.editor.search(text, "{} +{} char".format(

insert, length), nocase=caseInsensitive,

regexp=wholeWords)

if start:

self.editor.mark_set(tk.INSERT, start)

self.editor.see(start)

end = "{} +{} char".format(start, length)

self.editor.tag_add(FIND_TAG, start, end)

return start, end

return None, None

开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:25,

示例3: select_all

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def select_all(self, event):

event.widget.tag_add(tk.SEL, "1.0", tk.END)

event.widget.mark_set(tk.INSERT, "1.0")

event.widget.see(tk.INSERT)

return "break"

开发者ID:nimaid,项目名称:LPHK,代码行数:7,

示例4: import_script

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def import_script(self, textbox, window):

name = tk.filedialog.askopenfilename(parent=window,

initialdir=files.SCRIPT_PATH,

title="Import script",

filetypes=load_script_filetypes)

if name:

text = files.import_script(name)

text = files.strip_lines(text)

textbox.delete("1.0", tk.END)

textbox.insert(tk.INSERT, text)

开发者ID:nimaid,项目名称:LPHK,代码行数:12,

示例5: update_index

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def update_index(event=None):

cursor_position = text.index(tk.INSERT)

cursor_position_pieces = str(cursor_position).split('.')

cursor_line = cursor_position_pieces[0]

cursor_char = cursor_position_pieces[1]

current_index.set('line: ' + cursor_line + ' char: ' + cursor_char + ' index: ' + str(cursor_position))

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:10,

示例6: highlight_line

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def highlight_line(event=None):

start = str(text.index(tk.INSERT)) + " linestart"

end = str(text.index(tk.INSERT)) + " lineend"

text.tag_add("sel", start, end)

return "break"

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:8,

示例7: highlight_word

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def highlight_word(event=None):

word_pos = str(text.index(tk.INSERT))

start = word_pos + " wordstart"

end = word_pos + " wordend"

text.tag_add("sel", start, end)

return "break"

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:9,

示例8: down_three_lines

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def down_three_lines(event=None):

current_cursor_index = str(text.index(tk.INSERT))

new_position = current_cursor_index + "+3l"

text.mark_set(tk.INSERT, new_position)

return "break"

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:8,

示例9: back_four_chars

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def back_four_chars(event=None):

current_cursor_index = str(text.index(tk.INSERT))

new_position = current_cursor_index + "-4c"

text.mark_set(tk.INSERT, new_position)

return "break"

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:8,

示例10: set_signed_in

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def set_signed_in(self, me):

"""

Configures the application as "signed in" (displays user's

name and disables the entry to input phone/bot token/code).

"""

self.me = me

self.sign_in_label.configure(text='Signed in')

self.sign_in_entry.configure(state=tkinter.NORMAL)

self.sign_in_entry.delete(0, tkinter.END)

self.sign_in_entry.insert(tkinter.INSERT, utils.get_display_name(me))

self.sign_in_entry.configure(state=tkinter.DISABLED)

self.sign_in_button.configure(text='Log out')

self.chat.focus()

# noinspection PyUnusedLocal

开发者ID:LonamiWebs,项目名称:Telethon,代码行数:17,

示例11: on_moved

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def on_moved(self, event=None):

state = tk.NORMAL if not self.editor.is_empty() else tk.DISABLED

self.editMenu.entryconfigure(FIND + ELLIPSIS, state=state)

self.findButton.config(state=state)

lineCol = self.editor.index(tk.INSERT).split(".")

self.positionLabel.config(text="↓{}→{}".format(lineCol[0],

lineCol[1]))

开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:9,

示例12: check

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def check():

textEdit.frame.config(borderwidth=2)

print("frame", textEdit.frame.cget("borderwidth"))

print("yscrollbar", textEdit.yscrollbar.fraction(5, 5))

textEdit.insert("end",

"This is a test of the method delegation.\n" * 20)

print("text", textEdit.text.index(tk.INSERT))

print("text", textEdit.index(tk.INSERT))

开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:10,

示例13: use_queues

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def use_queues(self, loops=5):

# Now using a class member Queue

while True:

q_item = self.gui_queue.get()

print(q_item)

self.scrol.insert(tk.INSERT, q_item + '\n')

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-Cookbook-Second-Edition,代码行数:8,

示例14: method_in_a_thread

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def method_in_a_thread(self, num_of_loops=10):

for idx in range(num_of_loops):

sleep(1)

self.scrol.insert(tk.INSERT, str(idx) + '\n')

# Running methods in Threads

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-Cookbook-Second-Edition,代码行数:8,

示例15: click_me

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def click_me(self):

self.action.configure(text='Hello ' + self.name.get())

bq.write_to_scrol(self)

sleep(2)

html_data = url.get_html()

print(html_data)

self.scrol.insert(tk.INSERT, html_data)

# Spinbox callback

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-Cookbook-Second-Edition,代码行数:11,

示例16: _spin

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def _spin(self):

value = self.spin.get()

self.scrol.insert(tk.INSERT, value + '\n')

# GUI Callback

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-Cookbook-Second-Edition,代码行数:7,

示例17: _spin

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import INSERT [as 别名]

def _spin(self):

value = self.spin.get()

print(value)

self.scrol.insert(tk.INSERT, value + '\n')

# GUI Callback

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-Cookbook-Second-Edition,代码行数:8,

注:本文中的tkinter.INSERT属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值