本文整理汇总了Python中ScrolledText.focus方法的典型用法代码示例。如果您正苦于以下问题:Python ScrolledText.focus方法的具体用法?Python ScrolledText.focus怎么用?Python ScrolledText.focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScrolledText
的用法示例。
在下文中一共展示了ScrolledText.focus方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: App
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import focus [as 别名]
#.........这里部分代码省略.........
self.create_widgets()
sys.stdout = TextEmit(self.st2, 'stdout')
sys.stderr = TextEmit(self.st2, 'stderr')
self.cached_dict_of_dict = {}
def set_style(self):
s = ttk.Style()
s.configure('TButton', padding=(5))
s.configure('TCombobox', padding=(5))
s.configure('exe.TButton', foreground='red')
def parse_data(self):
data_file = self.com.get()
print('\n[Data File]: %s' % data_file)
print('=' * 52)
user_input = self.st1.get('0.1', 'end-1c')
query_list = CSV_Dict.get_query_list(user_input)
if data_file and query_list:
if data_file not in self.cached_dict_of_dict:
c = CSV_Dict.from_raw_data(os.path.join(DATA_PAHT,
data_file))
current_dict = c.detailed_dict
self.cached_dict_of_dict[data_file] = current_dict
else:
current_dict = self.cached_dict_of_dict[data_file]
print('[Dictionary count]: %s\n' % len(current_dict.keys()))
print('\n' + '=' * 52)
CSV_Dict.do_query(query_list, current_dict)
print('===== [Mission Complete] =====\n')
else:
sys.stderr.write('----- [Mission Failed] -----\n')
print('\n')
def clear_output(self):
self.st2.configure(state='normal')
self.st2.delete('1.0', 'end')
self.st2.configure(state='disabled')
def show_summary_of_data_file(self):
data_file = os.path.join(DATA_PAHT, self.com.get())
base_name = self.com.get()
if not os.path.isfile(data_file):
sys.stderr.write('>>>>> [Error]: Data file does not exist: %s\n' %
data_file)
print('\n[Show Data File Summary] %s' % base_name)
print('=' * 52)
with open(data_file, 'r') as f:
for i, line in enumerate(f):
if i < SUMMARY_LINE:
print('[ %d ] %s' % (i, line.strip()))
else:
print('[ 10] ... ...')
print('[...] ... ...')
break
def create_widgets(self):
self.content = ttk.Frame(self.master, padding=(5))
self.b1 = ttk.Button(self.content, text='Clear Query')
self.combo_value = StringVar()
self.com = ttk.Combobox(self.content, textvariable=self.combo_value,
state='readonly')
if not os.path.isdir(DATA_PAHT):
os.mkdir(data_folder)
self.com['values'] = os.listdir(DATA_PAHT)
if len(self.com['values']) > 0:
self.com.current(0)
else:
sys.stderr.write('Please put csv data file in data folder and '
'restart this program.')
self.b2 = ttk.Button(self.content, text='Data Summary',
command=self.show_summary_of_data_file)
self.b3 = ttk.Button(self.content, text='Query', style='exe.TButton')
self.b4 = ttk.Button(self.content, text='Clear Log')
self.st1 = ScrolledText(self.content)
self.st2 = ScrolledText(self.content)
self.b1.grid(row=0, column=0, sticky=(W))
self.b2.grid(row=0, column=1, sticky=(E))
self.com.grid(row=0, column=1, sticky=(W+E))
self.b3.grid(row=0, column=2, sticky=(W))
self.b4.grid(row=0, column=3, sticky=(E))
self.st1.grid(row=1, column=0, columnspan=2, sticky=(W+E+S+N))
self.st2.grid(row=1, column=2, columnspan=2, sticky=(W+E+S+N))
self.content.grid(row=0, column=0, sticky=(W+E+S+N))
self.b1['command'] = lambda: self.st1.delete('0.1', 'end')
self.b3['command'] = self.parse_data
self.b4['command'] = self.clear_output
self.master.rowconfigure(0, weight=1)
self.master.columnconfigure(0, weight=1)
self.content.rowconfigure(0, weight=0)
self.content.rowconfigure(1, weight=1)
self.content.columnconfigure(0, weight=1)
self.content.columnconfigure(1, weight=1)
self.content.columnconfigure(2, weight=1)
self.content.columnconfigure(3, weight=1)
self.st1.focus()
示例2: __init__
# 需要导入模块: import ScrolledText [as 别名]
# 或者: from ScrolledText import focus [as 别名]
#.........这里部分代码省略.........
self.parent.bind_all("<Command-Option-N>", self.new_tab)
self.file_menu.add_separator()
self.file_menu.add_command(label="Open", command=self.open_command, accelerator="Cmd+O")
self.parent.bind_all("<Command-o>", self.open_command)
self.parent.bind_all("<Command-O>", self.open_command)
self.file_menu.add_command(label="Save", command=self.save_command, accelerator="Cmd+S")
self.parent.bind_all("<Command-s>", self.save_command)
self.parent.bind_all("<Command-S>", self.save_command)
self.file_menu.add_separator()
self.file_menu.add_command(label= "Quit", command= self.exit_program, accelerator="Cmd+W")
self.parent.bind_all("<Command-w>", self.exit_program)
self.parent.bind_all("<Command-W>", self.exit_program)
# Edit Menu
self.edit_menu = tk.Menu(self.menuBar, tearoff=0)
self.menuBar.add_cascade(label= "Edit", menu= self.edit_menu)
self.edit_menu.add_command(label = "Cut", command = self.cut_command, accelerator="Cmd+X")
self.parent.bind_all("<Command-Shift-x>", self.cut_command)
self.parent.bind_all("<Command-Shift-X>", self.cut_command)
self.edit_menu.add_command(label = "Copy", command = self.copy_command, accelerator="Cmd+C")
self.parent.bind_all("<Command-Shift-c>", self.copy_command)
self.parent.bind_all("<Command-Shift-C>", self.copy_command)
self.edit_menu.add_command(label = "Paste", command = self.paste_command, accelerator="Cmd+V")
self.parent.bind_all("<Command-Shift-v>", self.paste_command)
self.parent.bind_all("<Command-Shift-V>", self.paste_command)
self.edit_menu.add_separator()
self.edit_menu.add_command(label= "Find", command= self.find_command)
parent.config(menu=self.menuBar)
##################################################
def open_command(self, event=None):
file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Select a file')
if file != None:
contents = file.read()
self.textWidget.insert("1.0",contents)
file.close()
def save_command(self, event=None):
file = tkFileDialog.asksaveasfile(mode= 'w')
if file != None:
data = self.textWidget.get("1.0", END+'-1c') #strip trailing \n at EOF
file.write(data)
file.close()
def exit_program(self, event=None):
if tkMessageBox.askokcancel("Quit", "Are you sure you want to quit?"):
self.parent.destroy()
#Opens up new text widget correctly but screws up closing the parent window via the menu
def new_command(self, event=None):
win = Toplevel()
SimpleTextEditor.__init__(self, win)
#Currently under construction
def new_tab(self, event=None):
#self.parent.add(self.textWidget, text="new tab", state='normal')
new_frame = tk.Frame(self.parent)
self.parent.add(new_frame, text='new', state='normal')
def cut_command(self, event=None):
text = self.textWidget.get(SEL_FIRST, SEL_LAST)
self.textWidget.delete(SEL_FIRST, SEL_LAST)
self.textWidget.clipboard_clear()
self.textWidget.clipboard_append(text)
def copy_command(self, event=None):
text = self.textWidget.get(SEL_FIRST, SEL_LAST)
self.textWidget.clipboard_clear()
self.textWidget.clipboard_append(text)
def paste_command(self, event=None):
try:
text = self.textWidget.selection_get(selection= 'CLIPBOARD')
self.textWidget.insert(INSERT, text)
except TclError:
pass
def find_command(self):
# Currently only works for highlighted text and will only find one match to the string, not all of the instances
# Also does not work with key binding because of askstring hanging window bug :/
target = askstring('SimpleEditor', 'Search String?')
if target:
where = self.textWidget.search(target, INSERT, END)
if where:
print where
pastit = where + ('+%dc' % len(target))
self.textWidget.tag_add(SEL, where, pastit)
self.textWidget.mark_set(INSERT, pastit)
self.textWidget.see(INSERT)
self.textWidget.focus()
def about_command(self):
label = tkMessageBox.showinfo("About", "A super duper simple text editor. It's now available through github, thanks to Jason!")
#dummy function as a place holder while constructing further functionality
def dummy_funct(self, event=None):
print"The life of a function is often very lonely..."