本文整理汇总了Python中tkinter.ttk.Combobox.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Combobox.insert方法的具体用法?Python Combobox.insert怎么用?Python Combobox.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Combobox
的用法示例。
在下文中一共展示了Combobox.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EntryVidget
# 需要导入模块: from tkinter.ttk import Combobox [as 别名]
# 或者: from tkinter.ttk.Combobox import insert [as 别名]
#.........这里部分代码省略.........
# If the text is not changing.
# Set text changing flag on
self._is_changing = True
# If notify event
if notify:
# Notify pre-change event
self.handler_notify(
self.TEXT_CHANGE_SOON,
arg=notify_arg,
need_info=True,
)
# Cache the text
self._text = text
# If caller is not validator,
# need change text widget's value.
if not is_validator:
# Unmount the validator wrapper before changing text widget's value
self._validator_wrapper_unmount()
# Set text widget to NORMAL state
self.state_set(NORMAL)
# Delete the old text from text widget.
# This will not trigger validation because the validator wrapper
# has been unmounted.
self._text_widget.delete(0, END)
# Insert the new text into text widget.
self._text_widget.insert(0, text)
# Set text widget to previous state
self.state_set_back()
# Mount the validator wrapper after changing text widget's value
self._validator_wrapper_mount()
# If caller is validator
# no need change text widget's value.
# If the cached text is not EQ text widget's value
if self._text != self._text_widget.get():
# If caller is not validator
if not is_validator:
# Set changing flag off
self._is_changing = False
# Raise error
raise ValueError(
'Inconsistent state. `{}` != `{}`'.format(
repr(self._text),
repr(self._text_widget.get()),
)
)
# If caller is validator,
# this is normal because text widget's value will be updated after
# the validator returns.
# If notify event
if notify:
# Notify post-change event
示例2: run_with_gui
# 需要导入模块: from tkinter.ttk import Combobox [as 别名]
# 或者: from tkinter.ttk.Combobox import insert [as 别名]
def run_with_gui():
root = Tk()
root.title("PyEncConv")
def browse_in():
name = askopenfilename()
if name:
in_txt.delete(0, END)
in_txt.insert(END, name)
def browse_out():
name = asksaveasfilename()
if name:
out_txt.delete(0, END)
out_txt.insert(END, name)
# input file
f = Frame(root)
f.pack(anchor=W, fill=X)
Label(f, text="input file:").pack(side=LEFT)
in_txt = Entry(f)
in_txt.pack(fill=X, expand=True, side=LEFT)
in_browse = Button(f, text="browse...", command=browse_in)
in_browse.pack(side=LEFT)
def load_file():
try:
txt_area.delete(1.0, END)
in_enc = in_enc_cmb.get()
in_alias_lbl.config(text=(' '.join(get_alt_names(in_enc))))
with open(in_txt.get(), 'r', encoding=in_enc) as f:
txt_area.insert(END, f.read())
except IOError as e:
txt_area.insert(END, str(e))
except OSError as e:
txt_area.insert(END, str(e))
except LookupError as e:
txt_area.insert(END, str(e))
except Exception as e:
txt_area.insert(END, str(e))
# input encoding
f = Frame(root)
f.pack(anchor=W, fill=X)
Label(f, text="input encoding:").pack(side=LEFT)
in_enc_cmb = Combobox(f)
in_enc_cmb.pack(side=LEFT)
in_enc_cmb['values'] = enc_set
in_enc_cmb.insert(END, getpreferredencoding())
in_enc_cmb.bind('<Return>', lambda event:load_file())
in_alias_lbl = Label(f)
in_alias_lbl.pack(side=LEFT)
Button(root, text="Load for preview", command=load_file).pack(anchor=W)
def disable_output_file():
out_txt.config(state=DISABLED)
out_browse.config(state=DISABLED)
def enable_output_file():
out_txt.config(state=NORMAL)
out_browse.config(state=NORMAL)
# output file
out_choice = IntVar(value=1)
Radiobutton(root, text="overwrite original (after moving to .bak)",
variable = out_choice, value=1,
command=disable_output_file).pack(anchor=W)
f = Frame(root)
f.pack(anchor=W, fill=X)
Radiobutton(f, text="output file:",
variable = out_choice, value=2,
command=enable_output_file).pack(side=LEFT)
out_txt = Entry(f, state=DISABLED)
out_txt.pack(fill=X, expand=True, side=LEFT)
out_browse = Button(f, text="browse...", command=browse_out,
state=DISABLED)
out_browse.pack(side=LEFT)
# output encoding
f = Frame(root)
f.pack(anchor=W, fill=X)
Label(f, text="output encoding:").pack(side=LEFT)
out_enc_cmb = Combobox(f)
out_enc_cmb.pack(side=LEFT)
out_enc_cmb['values'] = enc_set
out_enc_cmb.insert(END, 'UTF-8')
out_alias_lbl = Label(f)
out_alias_lbl.pack(side=LEFT)
def convert():
try:
txt_area.delete(1.0, END)
in_enc = in_enc_cmb.get()
in_alias_lbl.config(text=(' '.join(get_alt_names(in_enc))))
out_enc = out_enc_cmb.get()
out_alias_lbl.config(text=(' '.join(get_alt_names(out_enc))))
src_file = in_txt.get()
#.........这里部分代码省略.........