本文整理汇总了Python中tkinter.Text方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.Text方法的具体用法?Python tkinter.Text怎么用?Python tkinter.Text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter
的用法示例。
在下文中一共展示了tkinter.Text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def __init__(self):
super().__init__()
self.text_area = TextArea(self, bg="white", fg="black", undo=True)
self.scrollbar = ttk.Scrollbar(orient="vertical", command=self.scroll_text)
self.text_area.configure(yscrollcommand=self.scrollbar.set)
self.line_numbers = tk.Text(self, bg="grey", fg="white")
first_100_numbers = [str(n+1) for n in range(100)]
self.line_numbers.insert(1.0, "\n".join(first_100_numbers))
self.line_numbers.configure(state="disabled", width=3)
self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.line_numbers.pack(side=tk.LEFT, fill=tk.Y)
self.text_area.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
self.bind_events()
示例2: tagDemo
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def tagDemo(self):
if self.btn9['text']=='Create tag named \'myTag\' at line 2':
self.btn9.config(text = 'Remove Tag')
self.text.tag_add('myTag', '2.0', '2.0 lineend')
self.btn10 = ttk.Button(self.master, text = 'Change myTag background to yellow', command = self.tagbgyellow)
self.btn10.pack()
self.btn11 = ttk.Button(self.master, text = 'Remove tag from 1st word of line 2', command = self.tagrm21word)
self.btn11.pack()
self.btn12 = ttk.Button(self.master, text = 'myTag Span', command = self.getTagSpan)
self.btn12.pack()
self.btn13 = ttk.Button(self.master, text = 'Show all Tags in Text widget', command = self.displayAllTags)
self.btn13.pack()
else:
self.btn9.config(text = 'Create tag named \'myTag\' at line 2')
self.text.tag_delete('myTag')
self.btn10.destroy()
self.btn11.destroy()
self.btn12.destroy()
self.btn13.destroy()
示例3: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def __init__(self, image, initialField, initialText):
frm = tk.Frame(root)
frm.config(background="white")
self.image = tk.PhotoImage(format='gif',data=images[image.upper()])
self.imageDimmed = tk.PhotoImage(format='gif',data=images[image])
self.img = tk.Label(frm)
self.img.config(borderwidth=0)
self.img.pack(side = "left")
self.fld = tk.Text(frm, **fieldParams)
self.initScrollText(frm,self.fld,initialField)
frm = tk.Frame(root)
self.txt = tk.Text(frm, **textParams)
self.initScrollText(frm,self.txt,initialText)
for i in range(2):
self.txt.tag_config(colors[i], background = colors[i])
self.txt.tag_config("emph"+colors[i], foreground = emphColors[i])
示例4: create_widgets
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def create_widgets(self, **kwargs):
"""
Widgets shown:
- The frame's title,
- The checkbutton to enable/disable displaying,
- The textbox.
"""
self.top_frame = tk.Frame(self)
tk.Label(self.top_frame,
text=kwargs.get('title', '')).grid(row=0, column=0)
tk.Checkbutton(self.top_frame,
variable=self.enabled_checkbox,
text="Display?").grid(row=0, column=1)
self.serial_monitor = tk.Text(self,
relief="sunken",
height=int(self.total_width / 10),
width=int(self.total_width),
font=tkFont.Font(size=kwargs.get("fontsize",
13)))
self.top_frame.grid(row=0)
self.serial_monitor.grid(row=1)
示例5: set
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def set(self, value, *args, **kwargs):
if type(self.variable) == tk.BooleanVar:
self.variable.set(bool(value))
elif self.variable:
self.variable.set(value, *args, **kwargs)
elif type(self.input) in (ttk.Checkbutton, ttk.Radiobutton):
if value:
self.input.select()
else:
self.input.deselect()
elif type(self.input) == tk.Text:
self.input.delete('1.0', tk.END)
self.input.insert('1.0', value)
else:
self.input.delete(0, tk.END)
self.input.insert(0, value)
示例6: get
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def get(self):
try:
if self.variable:
return self.variable.get()
elif type(self.input) == tk.Text:
return self.input.get('1.0', tk.END)
else:
return self.input.get()
except (TypeError, tk.TclError):
# happens when numeric fields are empty.
return ''
示例7: set
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def set(self, value, *args, **kwargs):
if type(self.variable) == tk.BooleanVar:
self.variable.set(bool(value))
elif self.variable:
self.variable.set(value, *args, **kwargs)
elif type(self.input).__name__.endswith('button'):
if value:
self.input.select()
else:
self.input.deselect()
elif type(self.input) == tk.Text:
self.input.delete('1.0', tk.END)
self.input.insert('1.0', value)
else:
self.input.delete(0, tk.END)
self.input.insert(0, value)
示例8: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def __init__(self, master, textvariable=None, *args, **kwargs):
tk.Frame.__init__(self, master)
# Init GUI
self._y_scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
self._text_widget = tk.Text(self, yscrollcommand=self._y_scrollbar.set, *args, **kwargs)
self._text_widget.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
self._y_scrollbar.config(command=self._text_widget.yview)
self._y_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
if textvariable is not None:
if not isinstance(textvariable, tk.Variable):
raise TypeError("tkinter.Variable type expected, {} given.".format(
type(textvariable)))
self._text_variable = textvariable
self.var_modified()
self._text_trace = self._text_widget.bind('<<Modified>>', self.text_modified)
self._var_trace = textvariable.trace("w", self.var_modified)
示例9: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def __init__(self, data, title='TextWindow', *args, **kwargs):
Toplevel.__init__(self, master=root, *args, **kwargs)
self.title(title)
self.text = Text(master=self, blockcursor=True, insertbackground='black', )
self.text.bind('<Alt-p>', lambda event:
self.text.yview(SCROLL, 1, 'page'), add=True)
self.text.bind('<Alt-o>', lambda evenet:
self.text.yview(SCROLL, -1, 'page'), add=True)
self.text.insert('1.0', data)
self.text.pack(side=LEFT, fill=BOTH, expand=True)
self.text.focus_set()
self.text.bind('<Escape>', lambda event: self.close())
self.text.bind('<Key-k>', lambda event: self.text.event_generate('<Up>'))
self.text.bind('<Key-j>', lambda event: self.text.event_generate('<Down>'))
self.protocol("WM_DELETE_WINDOW", self.close)
self.transient(root)
self.withdraw()
示例10: save_file_as
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def save_file_as(self, file_path=None):
# If there is no file path specified, prompt the user with a dialog which
# allows him/her to select where they want to save the file
if file_path is None:
file_path = filedialog.asksaveasfilename(
filetypes=(
("Text files", "*.txt"),
("Prolog files", "*.pl *.pro"),
("All files", "*.*"),
)
)
try:
# Write the Prolog rule editor contents to the file location
with open(file_path, "wb") as file:
self.write_editor_text_to_file(file)
self.file_path = file_path
return "saved"
except FileNotFoundError:
return "cancelled"
示例11: show
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def show (self) :
self.slave = tkinter.Toplevel()
self.slave.title(self.winTitle)
self.slave.resizable(width = 'false', height = 'false')
if self.Tools.isWin() :
self.slave.iconbitmap(self.Tools.getRes('biticon.ico'))
self.frame = tkinter.Frame(self.slave, bd = 0, bg="#444")
self.frame.pack(expand = True, fill = 'both', ipadx = '5', ipady = '5')
titleLabel = tkinter.Label(self.frame, text = self.app['title'], fg = '#ddd', bg="#444", font = ("Helvetica", "16", 'bold'), anchor = 'center')
titleLabel.grid(row = 0, column = 1, pady = 5)
version = str(self.app['ver']) + ' Build (' + str(self.app['build']) + ')'
verlabel = tkinter.Label(self.frame, text = 'Version : ' + version, fg = '#ddd', bg="#444", font = ("Helvetica", "10"), anchor = 'center')
verlabel.grid(row = 1, column = 1)
self.information = tkinter.Text(self.frame, height = 8, width = 35, bd = 0, fg = '#ddd', bg="#222", highlightthickness = 1, highlightcolor="#111", highlightbackground = '#111', selectbackground = '#116cd6', font = ("Helvetica", "12"))
self.information.grid(row = 2, column = 1, pady = 10)
self.information.insert('end', '更新检测中。。。')
self.frame.grid_columnconfigure(0, weight=1)
self.frame.grid_columnconfigure(2, weight=1)
示例12: updateInfo
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def updateInfo (self) :
if self.udInfo != [] :
if self.udInfo['version'] != '' :
version = str(self.udInfo['version'])
else :
version = str(self.app['ver']) + ' Build (' + str(self.app['build']) + ')'
verlabel = tkinter.Label(self.frame, text = 'Version : ' + version, fg = '#ddd', bg="#444", font = ("Helvetica", "10"), anchor = 'center')
verlabel.grid(row = 1, column = 1)
self.information = tkinter.Text(self.frame, height = 8, width = 35, bd = 0, fg = '#ddd', bg="#222", highlightthickness = 1, highlightcolor="#111", highlightbackground = '#111', selectbackground = '#116cd6', font = ("Helvetica", "12"))
self.information.grid(row = 2, column = 1, pady = 10)
self.information.delete('0.0', 'end')
self.information.insert('end', self.udInfo['msg'])
btn = tkinter.Button(self.frame, text = 'Download', width = 10, fg = '#222', highlightbackground = '#444', command = lambda target = self.udInfo['dUrl'] : webbrowser.open_new(target))
btn.grid(row = 3, column = 1)
else :
self.timer = self.frame.after(50, self.updateInfo)
示例13: showDlLink
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def showDlLink (self, link) :
window = tkinter.Toplevel()
window.title('下载链接')
window.resizable(width = 'false', height = 'false')
if self.Tools.isWin() :
window.iconbitmap(self.Tools.getRes('biticon.ico'))
topZone = tkinter.Frame(window, bd = 0, bg="#444")
topZone.pack(expand = True, fill = 'both')
textZone = tkinter.Text(topZone, height = 8, width = 50, bd = 10, bg="#444", fg = '#ddd', highlightthickness = 0, selectbackground = '#116cd6')
textZone.grid(row = 0, column = 0, sticky = '')
textZone.insert('insert', link)
dlBtn = tkinter.Button(topZone, text = '下载', width = 10, fg = '#222', highlightbackground = '#444', command = lambda url = link : webbrowser.open_new(url))
dlBtn.grid(row = 1, column = 0, pady = 5)
示例14: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def __init__(self, parent, **kwargs):
super().__init__(parent,
height=self.font_height,
highlightthickness=0,
bd=0,
bg="grey26",
fg="white",
font=self.font,
**kwargs)
# console_stdout.stream defined by ConsoleType
# add existing contents of stream to tk.Text widget
self.insert(tk.END, self.stream.read()) # pylint: disable=E1101
self['state'] = tk.DISABLED
# instance takes ownership of the stream
self.set_stream() # pylint: disable=E1101
# exactly the same as console_stdout but instance takes ownership of stderr
示例15: create_widgets
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import Text [as 别名]
def create_widgets(self):
''' Creates all widgets.
'''
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
xscrollbar = Scrollbar(self, orient=HORIZONTAL)
xscrollbar.grid(row=1, column=0, sticky=E+W)
yscrollbar = Scrollbar(self)
yscrollbar.grid(row=0, column=1, sticky=N+S)
self.text = Text(self, wrap=NONE,
xscrollcommand=xscrollbar.set,
yscrollcommand=yscrollbar.set)
self.text.bind("<Control-Key-a>", self.select_all)
self.text.bind("<Control-Key-A>", self.select_all)
self.text.grid(row=0, column=0, sticky=N+S+E+W)
xscrollbar.config(command=self.text.xview)
yscrollbar.config(command=self.text.yview)