Python tkinter.Text() Examples
The following are 30
code examples of tkinter.Text().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tkinter
, or try the search function
.
Example #1
Source File: editor.py From Python-Prolog-Interpreter with MIT License | 10 votes |
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"
Example #2
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 7 votes |
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)
Example #3
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #4
Source File: pykms_GuiMisc.py From py-kms with The Unlicense | 6 votes |
def __init__(self, master, radios, font, changed, **kwargs): tk.Frame.__init__(self, master) self.master = master self.radios = radios self.font = font self.changed = changed self.scrollv = tk.Scrollbar(self, orient = "vertical") self.textbox = tk.Text(self, yscrollcommand = self.scrollv.set, **kwargs) self.scrollv.config(command = self.textbox.yview) # layout. self.scrollv.pack(side = "right", fill = "y") self.textbox.pack(side = "left", fill = "both", expand = True) # create radiobuttons. self.radiovar = tk.StringVar() self.radiovar.set('FILE') self.create()
Example #5
Source File: ColorDelegator.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _color_delegator(parent): # htest # from tkinter import Toplevel, Text from idlelib.Percolator import Percolator top = Toplevel(parent) top.title("Test ColorDelegator") top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200, parent.winfo_rooty() + 150)) source = "if somename: x = 'abc' # comment\nprint\n" text = Text(top, background="white") text.pack(expand=1, fill="both") text.insert("insert", source) text.focus_set() p = Percolator(text) d = ColorDelegator() p.insertfilter(d)
Example #6
Source File: WidgetRedirector.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _widget_redirector(parent): # htest # from tkinter import Tk, Text import re root = Tk() root.title("Test WidgetRedirector") width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) root.geometry("+%d+%d"%(x, y + 150)) text = Text(root) text.pack() text.focus_set() redir = WidgetRedirector(text) def my_insert(*args): print("insert", args) original_insert(*args) original_insert = redir.register("insert", my_insert) root.mainloop()
Example #7
Source File: CallTipWindow.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _calltip_window(parent): # htest # from tkinter import Toplevel, Text, LEFT, BOTH top = Toplevel(parent) top.title("Test calltips") top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200, parent.winfo_rooty() + 150)) text = Text(top) text.pack(side=LEFT, fill=BOTH, expand=1) text.insert("insert", "string.split") top.update() calltip = CallTip(text) def calltip_show(event): calltip.showtip("(s=Hello world)", "insert", "end") def calltip_hide(event): calltip.hidetip() text.event_add("<<calltip-show>>", "(") text.event_add("<<calltip-hide>>", ")") text.bind("<<calltip-show>>", calltip_show) text.bind("<<calltip-hide>>", calltip_hide) text.focus_set()
Example #8
Source File: nemo_app.py From razzy-spinner with GNU General Public License v3.0 | 6 votes |
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])
Example #9
Source File: program13.py From python-gui-demos with MIT License | 6 votes |
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()
Example #10
Source File: texteditor.py From Tkinter-GUI-Programming-by-Example with MIT License | 6 votes |
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()
Example #11
Source File: test_formatparagraph.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_init_close(self): instance = fp.FormatParagraph('editor') self.assertEqual(instance.editwin, 'editor') instance.close() self.assertEqual(instance.editwin, None) # For testing format_paragraph_event, Initialize FormatParagraph with # a mock Editor with .text and .get_selection_indices. The text must # be a Text wrapper that adds two methods # A real EditorWindow creates unneeded, time-consuming baggage and # sometimes emits shutdown warnings like this: # "warning: callback failed in WindowList <class '_tkinter.TclError'> # : invalid command name ".55131368.windows". # Calling EditorWindow._close in tearDownClass prevents this but causes # other problems (windows left open).
Example #12
Source File: arduino_basics.py From crappy with GNU General Public License v2.0 | 6 votes |
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)
Example #13
Source File: text_frame_gui.py From pyDEA with MIT License | 6 votes |
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)
Example #14
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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 ''
Example #15
Source File: console.py From hwk-mirror with GNU General Public License v3.0 | 6 votes |
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
Example #16
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #17
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #18
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #19
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #20
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #21
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #22
Source File: PlayerView.py From moviecatcher with MIT License | 6 votes |
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)
Example #23
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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)
Example #24
Source File: SikuliGui.py From lackey with MIT License | 6 votes |
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)
Example #25
Source File: UpdateInfoView.py From moviecatcher with MIT License | 6 votes |
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)
Example #26
Source File: widgets.py From vy with MIT License | 6 votes |
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()
Example #27
Source File: UpdateInfoView.py From moviecatcher with MIT License | 6 votes |
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)
Example #28
Source File: AppInfoView.py From moviecatcher with MIT License | 5 votes |
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')) info = [ '简介: 就是瞎做来看电影的。', '功能: 自动搜索电影资源,获取下载链接,发送至百度云,实现在线观看/离线下载功能。', '使用方法: https://github.com/EvilCult/moviecatcher/wiki/Application-Guide', '特别感谢: cclauss (https://github.com/cclauss)\nMrLevo520 (https://github.com/MrLevo520)', ] titleFrame = tkinter.Frame(self.slave, bd = 0, bg="#444") titleFrame.pack(expand = True, fill = 'both', ipadx = '5') titleLabel = tkinter.Label(titleFrame, text="Movie Catcher", fg = '#ddd', bg="#444", font = ("Helvetica", "16", 'bold'), anchor = 'center') titleLabel.grid(row = 0, column = 1, pady = 5) warnlabel = tkinter.Label(titleFrame, text="By ~EvilCult", fg = '#ddd', bg="#444", font = ("Helvetica", "10"), anchor = 'center') warnlabel.grid(row = 1, column = 1) pilImage = PIL.Image.open(self.Tools.getRes('logo.png')) logoImg = PIL.ImageTk.PhotoImage(pilImage) imglabel = tkinter.Label(titleFrame, bd = 0, bg = '#444', image = logoImg, anchor = 'center') imglabel.img = logoImg imglabel.grid(row = 2, column = 1, pady = 5) information = tkinter.Text(titleFrame, height = 14, width = 35, bd = 0, fg = '#ddd', bg="#222", highlightthickness = 1, highlightcolor="#111", highlightbackground = '#111', selectbackground = '#116cd6', font = ("Helvetica", "12")) information.grid(row = 3, column = 1) for n in info : information.insert('end', n.split(': ')[0] + ':\n') information.insert('end', n.split(': ')[1] + '\r') versionlabel = tkinter.Label(titleFrame, text="Version: " + str(self.app['ver']) + ' (' + str(self.app['build']) + ')', fg = '#ddd', bg="#444", font = ("Helvetica", "10"), anchor = 'center') versionlabel.grid(row = 4, column = 1) titleFrame.grid_columnconfigure(0, weight=1) titleFrame.grid_columnconfigure(2, weight=1)
Example #29
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def create(self, **kwargs): return tkinter.Text(self.root, **kwargs)
Example #30
Source File: test_widgetredir.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def setUpClass(cls): requires('gui') cls.tk = Tk() cls.text = Text(cls.tk)