当前位置: 首页>>代码示例>>Python>>正文


Python ScrolledText.tag_configure方法代码示例

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


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

示例1: StringVar

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import tag_configure [as 别名]
menubar.add_cascade(label = "View",menu = viewmenu)

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)
开发者ID:markelonn,项目名称:Text-Editor,代码行数:33,代码来源:texteditor.py

示例2: diary

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import tag_configure [as 别名]
class diary(Frame):

 def __init__(self,rt):
    if rt == None:
      self.t=Tk()    #创建顶层窗口t
    else:
      self.t=Toplevel(rt) #使用toplevel窗口模式
    self.t.title("窗口- %d"%len(t1))
    Frame.__init__(self,rt)
    self.pack(fill=BOTH, expand=1)
    


    '''定义按钮'''
    '''Possible values are specified as compass directions:
    "n" (north, or top edge), "ne", (north-east, or top right corner), 
    "e", "se", "s", "sw", "w", "nw" or "center".
    Layout布局
    pack side :It can be top, bottom, left and right. The default is top
    color: color names (e.g. "red") or hex RGB codes (e.g. "#ff340a").
    anchor :Pack widget will be anchored to specific side if the width is less than space is assigned. The valid edges are n,e,w,s(东西南北)
    '''

    self.f=Frame(self,width=512)
    self.f.pack(expand=1,fill=BOTH)
   
    self.st=ScrolledText(self.f,background="beige")
    self.st.tag_configure('bold_italics', font=('Arial', 12, 'bold', 'italic'))
    self.st.tag_configure('big', font=('Verdana', 20, 'bold'))
    self.st.tag_configure('color', foreground='#476042', 
                        font=('Tempus Sans ITC', 12, 'bold'))
    self.st.pack(side=LEFT,fill=BOTH,expand=1)
    
    self.open = Button(self)
    self.open["text"] = "打开文件"
    self.open["fg"] = "Blue"
    self.open["command"] = self.diary_open_txt
    self.open.pack({"side":"left"})
    self.open.pack({"anchor":"nw"})
    
    self.newfile = Button(self)
    self.newfile["text"] = "新建"
    self.newfile["fg"] = "black"
    self.newfile["command"] = neweditor
    self.newfile.pack({"side":"left"})
    self.newfile.pack({"anchor":"nw"})
   
    self.save = Button(self)
    self.save["text"] = "保存"
    self.save["fg"] = "black" 
    self.save["command"] = self.savefile
    self.save.pack({"side":"left"})
    self.save.pack({"anchor":"n"})
    
    self.quit = Button(self)
    self.quit["text"] = "关闭"
    self.quit["fg"] = "red"
    self.quit["command"] = self.close
    self.quit.pack({"side":"left"})
    self.quit.pack({"anchor":"center"})

    self.guan_yu = Button(self)
    self.guan_yu["text"] = "关于"
    self.guan_yu["fg"] = "red"
    self.guan_yu["command"] = lambda:self.about1()
    '''lambda后面跟的是表达式,注意调用函数需要增加()
    可以多试试它,挺不错的'''
    self.guan_yu.pack({"side":"right"})
    self.guan_yu.pack({"anchor":"center"})

    self.contents = StringVar()
    self.ent=Entry(self,textvariable=self.contents)    #http://effbot.org/tkinterbook/entry.htm
    self.ent.pack({"side":"bottom"},expand=1,fill='x')
    self.ent.bind("<Enter>",self.entry_enter)
    
 def entry_enter(self,event):
    entry_text = self.contents.get()
    print entry_text
    self.st.insert(END,entry_text)
    self.ent.delete(0,'end') #输入完成清空输入框信息
    


#定义打开文件函数    
 def diary_open_txt(self):
    p1=END
    oname=askopenfilename(filetypes=[("文本文件","*.txt*")])
    txt_open=codecs.open(oname, 'r', "GB2312")
    txt_read=txt_open.read()
    print txt_read
    if oname:
     for line in txt_read:  #fileinput.input(oname): 更新为
      self.st.insert(p1,line,'color') #调用字体
    
    '''
    if oname:
        for line in fileinput.input(oname):  #fileinput.input(oname): 更新为
         self.st.insert(p1,line)
         '''

#.........这里部分代码省略.........
开发者ID:beyondcly,项目名称:OMOOC2py,代码行数:103,代码来源:main.py

示例3: __init__

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import tag_configure [as 别名]

#.........这里部分代码省略.........
            self.editor.insert('1.0',contents)
            infile.close()

    def save_file(self, save_as=False):
        data = self.editor.get('1.0', END+'-1c')
        save_as_file = None

        # if saving the file by creation
        if self.file == None or save_as == True:
            save_as_file = tkFileDialog.asksaveasfilename() # attempt to select the filename, the user can select cancel so check agian below

        # the above could result in None if the user cancels the dialog
        if save_as_file:
            self.file = save_as_file

        # final check, as both the above could result in None
        if self.file != None:
            outfile = open(self.file, 'w')
            outfile.write(data)
            outfile.close()

    def goto_line(self):
        lineno = tkSimpleDialog.askinteger('Textee', 'Goto line:')
        if lineno > 0:
            self.editor.mark_set(INSERT, lineno + 0.0) #convert to float
            self.editor.see(INSERT)
        self.editor.focus_set()

    def toggle_theme(self):
        if self.theme == 'light':
            self.editor.config(bg='black', fg='white', insertbackground='white',highlightcolor='black')
            self.editor.frame.config(bg='black')
            # theme for misspelled words
            self.editor.tag_configure("misspelled", foreground="red", underline=True)
            self.theme = 'dark'
        else:
            self.editor.config(bg='white', fg='black', insertbackground='black',highlightcolor='white')
            self.editor.frame.config(bg='white')
            # theme for misspelled words
            self.editor.tag_configure("misspelled", foreground="red", underline=True)
            self.theme = 'light'

    def toggle_wrap(self):
        # self.editor.cget('wrap') # gets the config value
        if not self.options.wrap.get():
            self.editor.config(wrap='none')
        else:
            self.editor.config(wrap='word')

    def find(self):
        find_text = tkSimpleDialog.askstring("Textee", "Enter text to search", initialvalue=self.find_text)
        if find_text:
            if find_text == self.find_text:
                start_pos = self.editor.search(find_text, self.editor.index('insert'), stopindex=END, nocase=True)
            else:
                start_pos = self.editor.search(find_text, '1.0', stopindex=END, nocase=True)
                
            self.find_text = find_text
            if(start_pos):
                end_pos = '%s+%sc' % (start_pos, len(self.find_text))
                self.editor.tag_add(SEL, start_pos, end_pos)
                self.editor.mark_set(INSERT, end_pos) # mark the cursor to end of find text to start editing
                self.editor.see(INSERT) # bing the cursor position in the viewport incase of long text causinng scrollbar
                self.editor.focus_set() # strangely tkinter doesnt return focus after prompt
            else:
                tkMessageBox.showinfo("Textee", "No morw matches found")
开发者ID:rajeshvaya,项目名称:playground-textee,代码行数:70,代码来源:Textee.py


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