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


Python ScrolledText.focus_set方法代码示例

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


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

示例1: Tk

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import focus_set [as 别名]
from common_imports import *
from tkFileDialog import *
from tkMessageBox import *
from tkFont import Font
from ScrolledText import *
import file_menu
import edit_menu
import format_menu
import help_menu

root = Tk()

root.title("Text Editor-Untiltled")
root.geometry("300x250+300+300")
root.minsize(width=400, height=400)

font = Font(family="Verdana", size=10)

text = ScrolledText(root, state='normal', height=400, width=400, wrap='word', font = font, pady=2, padx=3, undo=True)
text.pack(fill=Y, expand=1)
text.focus_set()

menubar = Menu(root)

file_menu.main(root,text,menubar)
edit_menu.main(root,text,menubar)
format_menu.main(root,text,menubar)
help_menu.main(root,text,menubar)
root.mainloop()
开发者ID:punithpatil,项目名称:tkinter-text-editor,代码行数:31,代码来源:main.py

示例2: __init__

# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import focus_set [as 别名]
class MainWnd:
    def __init__(self, parent):
        self.search_str = StringVar()
        self.parent = parent

        root.protocol("WM_DELETE_WINDOW", self.ask_quit)

        self.parent.title("snippets")
        self.parent.configure(padx=10, pady=10)
        self.parent.minsize(630, 480)
        self.create_widgets()

        db_path = os.path.join(abspath(dirname(__file__)), "snip.db")
        db_exists = os.path.isfile(db_path)
        self.connection = sqlite3.connect(db_path)
        self.connection.row_factory = dict_factory
        self.cursor = self.connection.cursor()

        if not db_exists:
            self.cursor.execute('create table snippet (caption, content)')

        self.fill_list()
        self.snip_content.focus_set()

    def ask_quit(self):
        if tkMessageBox.askokcancel("Quit", "You want to quit now?"):
            self.parent.destroy()

    def __del__(self):
        self.connection.close()

    def create_widgets(self):
        self.search_box = Entry(self.parent, textvariable=self.search_str)
        self.search_str.set("New snippet")
        self.search_box.pack(fill=X)

        self.toolbar_f = Frame(self.parent, pady=5)
        self.toolbar_f.pack(fill=X)

        self.newbtn = Button(self.toolbar_f, text="New", command=self.on_new)
        self.newbtn.pack(side=LEFT)

        self.savebtn = Button(self.toolbar_f, text="Save", command=self.on_save)
        self.savebtn.pack(side=LEFT)

        self.updatebtn = Button(self.toolbar_f, text="Update", command=self.on_update)
        self.updatebtn.pack(side=LEFT)

        self.delbtn = Button(self.toolbar_f, text="Delete", command=self.on_delete)
        self.delbtn.pack(side=LEFT)

        self.copybtn = Button(self.toolbar_f, text="Copy to clipboard", command=self.on_copy)
        self.copybtn.pack(side=LEFT)

        self.quitbtn = Button(self.toolbar_f, text="Quit", command=self.on_quit)
        self.quitbtn.pack(side=LEFT)

        self.pwin = PanedWindow(self.parent, showhandle=True)
        self.pwin.pack(fill=BOTH, expand=1)

        self.list_f = Frame(self.pwin)
        self.list_sb = Scrollbar(self.list_f, orient=VERTICAL)
        self.snip_list = Listbox(self.list_f, yscrollcommand=self.list_sb.set)
        self.list_sb.config(command=self.snip_list.yview)
        self.snip_list.bind('<ButtonRelease-1>', self.on_snippet_selected)
        self.snip_list.pack(side=LEFT, fill=BOTH, expand=1)
        self.list_sb.pack(side=RIGHT, fill=Y)
        self.pwin.add(self.list_f)
        self.pwin.paneconfigure(self.list_f, minsize=177)

        self.snippetFont = Font(family="courier", size=11, weight=NORMAL)
        self.snip_content = ScrolledText(self.pwin, height=20, width=40,
                                         padx=5, pady=5,
                                         font=self.snippetFont)
        self.pwin.add(self.snip_content)


    # noinspection PyTypeChecker
    def fill_list(self):
        self.snip_list.delete(0, END)
        self.cursor.execute('select * from snippet')
        for r in self.cursor.fetchall():
            self.snip_list.insert(END, r['caption'])

    def on_new(self):
        self.search_str.set("")
        self.snip_content.delete(1.0, END)

    def on_save(self):
        self.cursor.execute(
            'insert into snippet (caption,content) values (?,?)',
            (self.search_str.get(), self.snip_content.get(1.0, END),))
        self.connection.commit()
        self.fill_list()

    def on_update(self):
        self.cursor.execute(
            'update snippet set content=? where caption=?',
            (self.snip_content.get(1.0, END), self.search_str.get()))
        self.connection.commit()
#.........这里部分代码省略.........
开发者ID:cenan,项目名称:snpptmngr,代码行数:103,代码来源:snip.py

示例3: __init__

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

#.........这里部分代码省略.........

    def open_file(self):
        self.file = tkFileDialog.askopenfilename(parent=self.master,title='Select a file')
        if self.file != None and self.file != '':
            self.editor.delete('1.0', END+'-1c') # clear all the contents
            infile = open(self.file, 'r')
            contents = infile.read()
            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):
开发者ID:rajeshvaya,项目名称:playground-textee,代码行数:70,代码来源:Textee.py


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