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


Python Entry.bind方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class AddRestrictionDialog:
    def __init__(self, parent):
        self.parent = parent
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()

        self.gui.columnconfigure(0, weight=1)
        self.gui.columnconfigure(1, weight=1)

        Label(self.gui, text="Enzyme:").grid(row=0, column=0, sticky="e", padx=5)
        self.entryEnzyme = Entry(self.gui)
        self.entryEnzyme.grid(row=0, column=1, sticky="w", padx=5, pady=10)
        self.frameButtonGroup = Frame(self.gui)
        self.frameButtonGroup.grid(row=1, column=0, columnspan=2, pady=10)
        self.buttonOK = Button(self.frameButtonGroup, text=" OK ")
        self.buttonCancel = Button(self.frameButtonGroup, text=" Cancel ")
        self.buttonOK.grid(row=0, column=1, sticky="w", padx=5)
        self.buttonCancel.grid(row=0, column=0, sticky="e", padx=5)

        # Set (minimum + max) Window size
        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
        self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())

        self.entryEnzyme.focus()

        self.buttonOK.bind("<ButtonRelease>", self.actionOK)
        self.buttonCancel.bind("<ButtonRelease>", self.actionCancel)
        self.entryEnzyme.bind("<Return>", self.actionOK)

        self.gui.mainloop()

    #         self.gui.grab_release()
    #         self.gui.destroy()

    def actionOK(self, event):
        enzymeString = self.entryEnzyme.get()
        if enzymeString in rest_dict.keys():

            if enzymeString in self.parent.optimizer.restrictionEnzymeList:
                showinfo("", (enzymeString + " was already added to the list"))
                return

            self.parent.optimizer.restrictionEnzymeList.append(enzymeString)
            self.parent.guiRoot.event_generate("<<Update>>", when="tail")
            self.gui.destroy()
        else:
            showinfo("", (enzymeString + " is not a valid restriction enzyme"))

    def actionCancel(self, event):
        self.gui.destroy()
开发者ID:hoerldavid,项目名称:codonoptimizer,代码行数:54,代码来源:OptimizerMainWindow.py

示例2: __init__

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class App:
    def __init__(self, master):
        frame = Frame(master)
        frame.pack()

        self.entry = Entry(frame)
        self.entry.pack(side=LEFT)

        self.entry.bind('<Return>', self.on_click)

    def on_click(self, event):
        print('ENTER')
        self.entry.delete(0, 'end')
开发者ID:rzzzwilson,项目名称:Random-Stuff,代码行数:15,代码来源:test.py

示例3: AddManually

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class AddManually(Frame):

    def __init__(self, parent, controller):
        Frame.__init__(self, parent)
        self.controller = controller

        self.place(relx=0.0, rely=0.0, relheight=0.62, relwidth=0.72)
        self.configure(relief=GROOVE)
        self.configure(borderwidth="2")
        self.configure(relief=GROOVE)
        self.configure(width=125)

        self.label_top = Label(self)
        self.label_top.place(relx=0.4, rely=0.03, height=21, width=112)
        self.label_top.configure(text="Add items manually")

        self.name = Entry(self, fg='grey')
        self.name.place(relx=0.05, rely=0.31, relheight=0.08, relwidth=0.29)
        self.name.insert(0, "Input name here")
        self.name.bind('<Button-1>', lambda event: greytext(self.name))

        self.link = Entry(self, fg='grey')
        self.link.place(relx=0.65, rely=0.31, relheight=0.08, relwidth=0.29)
        self.link.insert(0, "Input link here")
        self.link.bind('<Button-1>', lambda event: greytext(self.link))

        self.add_btn = Button(self, command=self.send_data)
        self.add_btn.place(relx=0.42, rely=0.44, height=34, width=100)
        self.add_btn.configure(text="Add item")

        self.back = Button(self, command=lambda: controller.show_frame('Main'))
        self.back.place(relx=0.42, rely=0.64, height=34, width=100)
        self.back.configure(text="Go back")

        name_label = Label(self)
        name_label.place(relx=0.05, rely=0.22, height=21, width=38)
        name_label.configure(text="Name")

        link_label = Label(self)
        link_label.place(relx=0.65, rely=0.22, height=21, width=28)
        link_label.configure(text="Link")

    def send_data(self):
        if self.link.cget('fg') == 'grey' or self.name.cget('fg') == 'grey':
            return
        link = self.link.get()
        if link.strip() != '':
            name = self.name.get()
            self.controller.add_item(link, name)
            print("Item added")
开发者ID:s0hvaperuna,项目名称:Custom-playlist,代码行数:52,代码来源:addlink.py

示例4: __init__

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
    def __init__(self):
        super().__init__()
        self.title('Hangman')
        self.geometry('640x480+200+200')
        self.resizable(width=False, height=False)

        menu_bar = Menu(self, tearoff=0)
        self.config(menu=menu_bar)

        game_menu = Menu(menu_bar, tearoff=0)
        game_menu.add_command(label='New game', command=self.__on_new_game)
        game_menu.add_command(label='Quit', command=self.__on_quit)
        menu_bar.add_cascade(label='Game', menu=game_menu)

        self.__hang_canvas = Canvas(self, background='#ffffff')
        self.__hang_canvas.pack(fill=BOTH, expand=True)

        self.__dict_filename = os.path.join(os.path.dirname(__file__), 'dictionary.txt')
        self.__dictionary = []
        self.__secret_word_masked = StringVar()
        self.__game_stages = (
            # (is_circle, x1, y1, x2, y2),
            (False, 50, 300, 200, 300), # podstawa
            (False, 60, 300, 60, 10), # maszt
            (False, 60, 10, 160, 10),
            (False, 60, 30, 100, 10),
            (False, 160, 10, 160, 30),
            (True, 140, 30, 180, 70),
            (False, 160, 70, 160, 200), # tułów
            (False, 140, 120, 160, 70), # lewa reka
            (False, 180, 120, 160, 70), # prawa ręka
            (False, 160, 200, 140, 250),
            (False, 160, 200, 180, 250)
        )
        self.__errors_count = 0

        secret_word_label = Label(self, font=('purisa', 36), textvariable=self.__secret_word_masked)
        secret_word_label.pack(fill=X)

        # user input panel
        Label(self, text='Please input a char:').pack(fill=X)
        self.__user_input_char = StringVar()
        user_input_entry = Entry(self, textvariable=self.__user_input_char)
        user_input_entry.bind('<Return>', self.__on_user_input)
        user_input_entry.pack()

        self.__load_dictionary()
        self.__new_game()
开发者ID:4544fa8d,项目名称:Hangman,代码行数:50,代码来源:hangman.py

示例5: main

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
def main():
    root = Tk()
    root.title('Basic calculator')

    Label(root, text="Enter an arithmetic expression:").grid(row=0,column=0, columnspan=2)

    ent = Entry(root)
    # Make the entry evaluate upon return
    # The e is the event triggered by the return which we ignore
    ent.bind("<Return>", lambda e: evaluate(ent))
    ent.grid(row=1, column=0, columnspan=2)

    Button(master=root, text="Evaluate", command=lambda: evaluate(ent)).grid(row=2, column=0)
    Button(root, text="Clear", command=lambda: ent.delete(0, END)).grid(row=2, column=1)
    
    root.mainloop()
开发者ID:brandonPauly,项目名称:pythonToys,代码行数:18,代码来源:basic_calcWithEnter.py

示例6: Game

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class Game(Frame):
    'Number guessing application'
    def __init__(self,parent=None):
        'constructor'
        Frame.__init__(self, parent)
        self.pack()
        Game.make_widgets(self)
        Game.new_game(self)
        

    def make_widgets(self):
        'defines Game widgets'
        Label(self,text='Enter your guess:').pack()
        self.ent=Entry(self)
        self.ent.pack()
        Button(self,text='Enter',command=self.reply).pack()
        self.ent.bind('<Return>', lambda e: self.reply())

    def new_game(self):
        'starts a new game by choosing secret number'
        self.secNum=randrange(1,101) 

    def reply(self):
        'handles button "Enter" clicks'
        try:
            guess=eval(self.ent.get())
            num=self.secNum
            if guess > num:
                showinfo(title='Report',message='{} is too high!'.format(guess))
            elif guess < num:
                showinfo(title='Report',message='{} is too low!'.format(guess))
            else:
                showinfo(title='Report',message='You got it!')
                Game.new_game(self)
        except:
            showinfo(title='Ooops!',message='Invalid number!')
        self.ent.delete(0,END)
开发者ID:brandonPauly,项目名称:pythonToys,代码行数:39,代码来源:csc242hw5.py

示例7: ReadFromFile

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class ReadFromFile(Frame):

    def __init__(self, parent, controller):
        Frame.__init__(self, parent)
        self.controller = controller
        self.link_first = True
        self.items = []

        self.place(relx=0.0, rely=0.0, relheight=0.62, relwidth=0.72)
        self.configure(relief=GROOVE)
        self.configure(borderwidth="2")

        label_top = Label(self)
        label_top.place(relx=0.42, rely=0.03, height=21, width=105)
        label_top.configure(text="Select a file to read")

        self.file_select = Button(self, command=self.fopen)
        self.file_select.place(relx=0.43, rely=0.14, height=34, width=97)
        self.file_select.configure(text="Select file")

        self.back = Button(self, command=lambda: controller.show_frame('Main'))
        self.back.place(relx=0.8, rely=0.87, height=34, width=97)
        self.back.configure(text="Go back")

        self.delimeter = Entry(self)
        self.delimeter.place(relx=0.02, rely=0.11, relheight=0.06, relwidth=0.21)
        self.delimeter.insert(0, ' -<>- ')

        label_delim = Label(self)
        label_delim.place(relx=0.02, rely=0.03, height=21, width=57)
        label_delim.configure(text="Delimeter")

        self.switch_label = Label(self)
        self.switch_label.place(relx=0.73, rely=0.31, height=21, width=38)
        self.switch_label.configure(text="Link")

        self.switch_label2 = Label(self)
        self.switch_label2.place(relx=0.9, rely=0.31, height=21, width=38)
        self.switch_label2.configure(text="Name")

        self.change_order = Button(self, command=self.switch_order)
        self.change_order.place(relx=0.82, rely=0.31, height=24, width=32)
        self.change_order.configure(text="<->")

        name_or_link = Label(self)
        name_or_link.place(relx=0.75, rely=0.19, height=21, width=97)
        name_or_link.configure(text="Name or link first")

        self.items_text = Text(self)
        self.items_text.place(relx=0.02, rely=0.5, relheight=0.46, relwidth=0.76)
        self.items_text.configure(wrap=tk.WORD)

        label_items = Label(self)
        label_items.place(relx=0.35, rely=0.42, height=21, width=35)
        label_items.configure(text="Items")

        self.commit_btn = Button(self, command=self.commit)
        self.commit_btn.place(relx=0.83, rely=0.64, height=34, width=67)
        self.commit_btn.configure(text="Commit")

        self.Label12 = Label(self)
        self.Label12.place(relx=0.02, rely=0.19, height=21, width=88)
        self.Label12.configure(text="Link formatting (optional)")

        self.link_part1 = Entry(self, fg='grey')
        self.link_part1.place(relx=0.02, rely=0.28, relheight=0.06, relwidth=0.37)
        self.link_part1.insert(0, "Start of the link here")
        self.link_part1.bind('<Button-1>', lambda event: greytext(self.link_part1))

        self.link_part2 = Entry(self, fg='grey')
        self.link_part2.place(relx=0.02, rely=0.36, relheight=0.06, relwidth=0.37)
        self.link_part2.insert(0, "End of the link here")
        self.link_part2.bind('<Button-1>', lambda event: greytext(self.link_part2))

    def fopen(self):
        filename = askopenfilename()
        if filename == '':
            return
        self.items.clear()
        self.items_text.delete(1.0, 'end')
        with open(filename, encoding='utf-8-sig') as f:
            lines = f.read().splitlines()

        delim = self.delimeter.get()
        for line in lines:
            try:
                link, name = line.split(delim, 1)
                if not self.link_first:
                    name, link = link, name
                if '{DELETED} ' in name[:13]:
                    continue
                s, e = self.get_link_formatting()
                link = s + link + e
                self.items += [(link, name)]
                self.items_text.insert('end', ("name: " + name + "\nlink: " +
                                               link + '\n\n'))
            except ValueError:
                print("Something went wrong: ", line)

    def get_link_formatting(self):
#.........这里部分代码省略.........
开发者ID:s0hvaperuna,项目名称:Custom-playlist,代码行数:103,代码来源:addlink.py

示例8: Application

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class Application(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.send_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.bind((host, port))
        self.grid()
        self.columnconfigure(0, minsize=100)
        self.columnconfigure(1, minsize=200)
        self.columnconfigure(2, minsize=200)
        self.columnconfigure(3, minsize=150)
        self.columnconfigure(4, minsize=150)
        self.columnconfigure(5, minsize=150)
        self.columnconfigure(6, minsize=150)
        self.create_widgets()
        self.settables = self.assemble_settables()
        self.gui_logger = logging.getLogger('gui')
        self.request_update()

    def create_widgets(self):
        self.create_monitor()
        self.create_check_buttons()
        self.create_ranges()
        self.create_scales()
        self.create_radio_buttons()
        self.create_voices()
        self.quitButton = Button(self, text='Quit', command=self.quit)
        self.quitButton.grid(columnspan=7, sticky=E + W)

    def assemble_settables(self):
        settables = self.winfo_children()
        for w in settables:
            settables += w.winfo_children()
        return [w for w in settables if w.__class__.__name__ in ['Scale', 'Checkbutton']]

    def create_radio_buttons(self):
        # Scale related
        entries = ['DIATONIC', 'HARMONIC', 'MELODIC', 'PENTATONIC', 'PENTA_MINOR',
                   'GREEK_CHROMATIC', 'GREEK_ENHARMONIC']
        self.scale = StringVar()
        self.scale.set('DIATONIC')
        self.rb_frame = Frame(self)
        for e in entries:
            rb = Radiobutton(self.rb_frame, value=e, text=e, anchor=W,
                             command=self.send_scale, variable=self.scale)
            rb.grid(row=len(self.rb_frame.winfo_children()), sticky=W)
        self.rb_frame.grid(column=1, row=len(self.grid_slaves(column=1)), rowspan=3)

    def create_monitor(self):
        self.monitor_frame = LabelFrame(self, text="Monitor and Transport")
        this_cycle = Scale(self.monitor_frame, label='cycle_pos', orient=HORIZONTAL,
                           from_=1, to=16, resolution=1)
        this_cycle.disable, this_cycle.enable = (None, None)
        this_cycle.ref = 'cycle_pos'
        this_cycle.grid(column=0, row=0, sticky=E + W)
        self.updateButton = Button(self.monitor_frame,
                                   text='Reload all Settings',
                                   command=self.request_update)
        self.updateButton.grid(row=1, sticky=E + W)
        self.ForceCaesuraButton = Button(self.monitor_frame,
                                         text='Force Caesura',
                                         command=self.force_caesura)
        self.ForceCaesuraButton.grid(row=2, sticky=E + W)
        self.saveBehaviourButton = Button(self.monitor_frame,
                                          text='Save current behaviour',
                                          command=self.request_saving_behaviour)
        self.saveBehaviourButton.grid(row=3, sticky=E + W)
        self.saveBehaviourNameEntry = Entry(self.monitor_frame)
        self.saveBehaviourNameEntry.grid(row=4, sticky=E + W)
        self.saveBehaviourNameEntry.bind('<KeyRelease>', self.request_saving_behaviour)
        self.selected_behaviour = StringVar()
        self.selected_behaviour.trace('w', self.new_behaviour_chosen)
        self.savedBehavioursMenu = OptionMenu(self.monitor_frame,
                                              self.selected_behaviour, None,)
        self.savedBehavioursMenu.grid(row=5, sticky=E + W)
        self.monitor_frame.grid(column=0, row=10, sticky=E + W)

    def request_update(self):
        self.send({'sys': 'update'})

    def request_saving_behaviour(self, event=None):
        """callback for save behaviour button and textentry"""
        if event and event.widget == self.saveBehaviourNameEntry:
            if event.keysym == 'Return':
                name = self.saveBehaviourNameEntry.get()
                self.saveBehaviourNameEntry.delete(0, len(name))
            else:
                return
        else:  # button was pressed
            name = self.saveBehaviourNameEntry.get()
        if name:
            self.send({'sys': ['save_behaviour', name]})

    def force_caesura(self):
        self.send({'force_caesura': True})

    def create_voices(self):
        voice_ids = ['1', '2', '3', '4']
        SCALES = OrderedDict([
                  ('pan_pos', {'min': -1, 'max': 1, 'start': 0.5, 'res': 0.001}),
#.........这里部分代码省略.........
开发者ID:kr1,项目名称:roqba,代码行数:103,代码来源:main.py

示例9: metric_entry

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
def metric_entry(parent, **config):
    global the_metric_entry
    the_metric_entry = Entry(parent, **config)
    the_metric_entry.bind("<KeyRelease>", lambda event: the_metric_entry.config(bg="white"))
    return the_metric_entry
开发者ID:walg,项目名称:database,代码行数:7,代码来源:__init__.py

示例10: Main

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class Main(Frame):
    def __init__(self, parent, controller):
        Frame.__init__(self, parent)
        self.controller = controller
        self.db_set = False

        self.configure(relief=GROOVE)
        self.configure(borderwidth="2")

        # Manual link adding
        self.manual_btn = Button(self)
        self.manual_btn.place(relx=0.07, rely=0.81, height=45, width=130)
        self.manual_btn.configure(activebackground="#d9d9d9")
        self.manual_btn.configure(highlightbackground="#d9d9d9")
        self.manual_btn.configure(pady="0")
        self.manual_btn.configure(text="Add manually")
        self.manual_btn.configure(width=130)

        self.file_btn = Button(self)
        self.file_btn.place(relx=0.67, rely=0.81, height=45, width=150)
        self.file_btn.configure(activebackground="#d9d9d9")
        self.file_btn.configure(highlightbackground="#d9d9d9")
        self.file_btn.configure(pady="0")
        self.file_btn.configure(text="Add from file")

        self.label = Label(self)
        self.label.place(relx=0.08, rely=0.0, height=61, width=484)
        self.label.configure(text="Create new playlists and add content to them")
        self.label.configure(width=485)

        self.listbox = Listbox(self)
        self.listbox.place(relx=0.38, rely=0.22, relheight=0.31, relwidth=0.17)
        self.listbox.configure(background="white")
        self.listbox.configure(disabledforeground="#a3a3a3")
        self.listbox.configure(foreground="#000000")
        self.listbox.configure(selectmode=SINGLE)
        self.listbox.configure(width=105)
        for name, value in config.configparser.items('Playlists'):
            if os.path.isdir(value):
                self.listbox.insert('end', name)
            else:
                config.remove_value('Playlists', name)
        self.listbox.bind('<<ListboxSelect>>', self.onselect)

        self.label_name = Label(self)
        self.label_name.place(relx=0.7, rely=0.22, height=31, width=84)
        self.label_name.configure(foreground="#000000")
        self.label_name.configure(text="Name")
        self.label_name.configure(width=85)

        self.entry = Entry(self)
        self.entry.place(relx=0.63, rely=0.31, relheight=0.08, relwidth=0.29)
        self.entry.configure(background="white")
        self.entry.configure(foreground="#000000")
        self.entry.configure(insertbackground="black")
        self.entry.configure(takefocus="0")
        self.entry.configure(width=175)

        self.change_name = Button(self)
        self.change_name.place(relx=0.7, rely=0.42, height=34, width=97)
        self.change_name.configure(activebackground="#d9d9d9")
        self.change_name.configure(highlightbackground="#d9d9d9")
        self.change_name.configure(highlightcolor="black")
        self.change_name.configure(pady="0")
        self.change_name.configure(text="Rename")
        self.change_name.configure(width=100)

        self.new_playlist = Button(self, command=self.new_database)
        self.new_playlist.place(relx=0.08, rely=0.28, height=54, width=107)
        self.new_playlist.configure(activebackground="#d9d9d9")
        self.new_playlist.configure(highlightbackground="#d9d9d9")
        self.new_playlist.configure(highlightcolor="black")
        self.new_playlist.configure(pady="0")
        self.new_playlist.configure(text="Create new playlist")
        self.new_playlist.configure(width=105)

        self.db_name = Entry(self)
        self.db_name.place(relx=0.07, rely=0.44, relheight=0.08, relwidth=0.22)
        self.db_name.configure(fg='grey')
        self.db_name.configure(width=135)
        self.db_name.insert(0, "Input database name here")
        self.db_name.bind('<Button-1>', lambda event: greytext(self.db_name))

    def onselect(self, event):
        w = event.widget
        index = int(w.curselection()[0])
        value = w.get(index)
        set_database(config.configparser.get('Playlists', value))
        if not database.check_integrity():
            messagebox.showwarning('Integrity check failed', 'You might be missing some entries in your list')
        if not self.db_set:
            self.manual_btn.configure(command=lambda: self.controller.show_frame('AddManually'))
            self.file_btn.configure(command=lambda: self.controller.show_frame('ReadFromFile'))
            self.db_set = True

    def new_database(self):
        name = self.db_name.get()
        names = config.configparser.options('Playlists')
        print(name, names)
        if name.strip() == '' or self.db_name.cget('fg') == 'grey':
#.........这里部分代码省略.........
开发者ID:s0hvaperuna,项目名称:Custom-playlist,代码行数:103,代码来源:addlink.py

示例11: QuizMe

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class QuizMe(Frame):

    PROMPT = 'What testbank do you want to open?'

    def __init__(self, master):
        # Initialize the Frame object.
        super().__init__(master)
        # Create every opening widget.
        self.intro = Label(self, text=self.PROMPT)
        self.group = LabelFrame(self, text='Filename')
        self.entry = Entry(self.group, width=35)
        self.click = Button(self.group, text='Browse ...', command=self.file)
        self.enter = Button(self, text='Continue', command=self.start)
        # Make Windows entry bindings.
        def select_all(event):
            event.widget.selection_range(0, tkinter.END)
            return 'break'
        self.entry.bind('<Control-Key-a>', select_all)
        self.entry.bind('<Control-Key-/>', lambda event: 'break')
        # Position them in this frame.
        options = {'sticky': tkinter.NSEW, 'padx': 5, 'pady': 5}
        self.intro.grid(row=0, column=0, **options)
        self.group.grid(row=1, column=0, **options)
        self.entry.grid(row=0, column=0, **options)
        self.click.grid(row=0, column=1, **options)
        self.enter.grid(row=2, column=0, **options)

    def file(self):
        # Find filename for self.entry
        options = {'defaultextension': '.xml',
                   'filetypes': [('All', '*'), ('XML', '.xml')],
                   'initialdir': os.path.join(os.getcwd(), 'tests'),
                   'parent': self,
                   'title': 'Testbank to Open'}
        filename = askopenfilename(**options)
        if filename:
            self.entry.delete(0, tkinter.END)
            self.entry.insert(0, filename)

    def start(self):
        # Validate self.entry and begin
        path = self.entry.get()
        if os.path.exists(path):
            if os.path.isfile(path):
                try:
                    bank = testbank.parse(path)
                    engine = teach_me.FAQ(bank)
                except xml.sax._exceptions.SAXParseException as error:
                    title = error.getMessage().title()
                    LN = error.getLineNumber()
                    CN = error.getColumnNumber()
                    message = 'Line {}, Column {}'.format(LN, CN)
                    showerror(title, message, master=self)
                except AssertionError as error:
                    title = 'Validation Error'
                    message = error.args[0]
                    showerror(title, message, master=self)
                except:
                    title = 'Error'
                    message = 'Unknown exception was thrown!'
                    showerror(title, message, master=self)
                else:
                    self.done = False
                    self.next_event = iter(engine).__next__
                    self.after_idle(self.execute_quiz)
            else:
                title = 'Warning'
                message = 'File does not exist.'
                showwarning(title, message, master=self)
        else:
            title = 'Information'
            message = 'Path does not exist.'
            showinfo(title, message, master=self)

    def execute_quiz(self):
        # Follow the logic from the last program.
        # This will be called to handle an event.
        try:
            event = self.next_event()
        except StopIteration:
            assert self.done, 'Final event not processed!'
        else:
            if isinstance(event, teach_me.Enter):
                gui_logs.ShowStatus(self, 'Entering', event, self.execute_quiz)
            elif isinstance(event, teach_me.Exit):
                gui_logs.ShowStatus(self, 'Exiting', event, self.execute_quiz)
                self.last_exit = event.kind
            elif isinstance(event, teach_me.Question):
               gui_logs. AskQuestion(self, event, self.execute_quiz)
            elif isinstance(event, teach_me.Report):
                flag = [True]
                if self.last_exit == 'Section' and event.wrong:
                    flag[0] = False
                    gui_logs.ReviewProblems(self, event, flag)
                if flag[0]:
                    gui_logs.ShowReport(self, event, self.execute_quiz)
                if event.final:
                    title = 'Congratulations!'
                    message = 'You have finished the test.'
                    showinfo(title, message, master=self)
#.........这里部分代码省略.........
开发者ID:jacob-carrier,项目名称:code,代码行数:103,代码来源:recipe-577525.py

示例12: RpgWindow

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class RpgWindow(Frame):
	
	def __init__(self,parent):
		Frame.__init__(self,parent)
		self.parent = parent
		#set up world and engine
		self.w = World()
		self.game_out_q = Queue()
		self.game_in_q = Queue()
		self.game_engine = GameEngine(world=self.w,queue=self.game_out_q,outqueue=self.game_in_q)
		self.game_engine.start()
		self.centerWindow()
		self.player_input = StringVar('')
		self.currentInterpreter = None
		self.baseInterpreter = None
		#fonts for highlighting targets
		self.output_stream_writer = None
		self.looktargets_font = font.Font(family="Helvetica",size=10,weight="bold")
		self.exits_font = font.Font(family="Helvetica",size=10,weight="bold",underline=True)
		#go go go
		self.initUI()
	
	def killBabies(self):
		print('killing babies')
		self.game_engine.exit = True
		self.currentInterpreter.exit = True
	
	def get_engine_output(self):
		messages = []
		go = False
		#check if we have new messages from game engine
		while not self.game_in_q.empty():
			messages.append(self.game_in_q.get())
			go = True
		#process messages if we have any
		if go:
			for message in messages:
				print(message)
				if 'display' == message[0]:
					self.output.insert(END,message[1])
					self.output.see(END)
					self.status_output.delete(1.0, END)
					self.status_output.insert(END, 'You are in %s' % self.game_engine.current_room.roomname)
					for target in self.game_engine.current_room.looktargets.keys():
						if target not in self.game_engine.current_room.hide_looktargets:
							self.output.highlight_pattern(target, 'looktargets')
					self.status_output.insert(END, '\n\nExits\n=========\n')
					for target in self.game_engine.current_room.exits.keys():
						if target not in self.game_engine.current_room.hide_exits:
							self.output.highlight_pattern(target, 'exits')
							self.status_output.insert(END,'%s\n' % target)
					if self.game_engine.current_room.characters:
						self.status_output.insert(END, '\n\nCharacters\n=========\n')
						for target in self.game_engine.current_room.characters:
							self.status_output.insert(END, target)
				if 'dialogue' == message[0]:
					self.currentInterpreter = self.currentInterpreter.start_dialogue(message[1])
					self.status_output.delete(1.0, END)
					self.status_output.insert(END, 'You are in %s' % self.game_engine.current_room.roomname)
					self.status_output.insert(END, '\nYou are talking to %s\n' % message[1])
				if 'combat' == message[0]:
					self.currentInterpreter = self.baseInterpreter
					self.currentInterpreter = self.currentInterpreter.start_combat(message[1])
					self.status_output.delete(1.0, END)
					self.output.insert(END,'\n=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=\nPrepare to Fight!\n\n\n')
					self.output.see(END)					
					self.status_output.insert(END, 'You are in %s' % self.game_engine.current_room.roomname)
					self.status_output.insert(END, '\nYou are Fighting %s\n' % message[1])
				if 'exit' == message[0]:
					self.currentInterpreter = self.baseInterpreter
					self.output.insert(END,'Exiting...\n\n')
					self.output.see(END)					

		#call ourself again
		self.after(1,self.get_engine_output)
	
	def get_player_input(self,player_input):
		#clear the entry object
		self.currentInterpreter.stdin = StringIO(self.player_input.get() + '\n')
		self.currentInterpreter.cmdloop(stop=False)
		self.player_console.delete(0, END)
		self.after_idle(self.get_engine_output)		
	
	def initUI(self):
		self.parent.title('RPG -- Really Pretty Good')
		#set up input/output console
		self.player_console = Entry(self.parent,textvariable=self.player_input)
		self.player_console.bind('<Return>', self.get_player_input)
		#set up output console
		self.output = RPGText(self.parent,wrap='word',height=29,width=80,bg='grey')
		self.status_output = RPGText(self.parent,wrap='word',height=4,width=20)
		self.output.tag_config('looktargets', font=self.looktargets_font)
		self.output.tag_config('exits', font=self.exits_font)
		
		#do whatever pack does
		#self.pack(fill = BOTH,expand = 1)
		self.status_output.pack(fill=BOTH,expand=1,side=RIGHT)
		self.output.pack(fill=BOTH,expand=1,side=TOP)
		self.player_console.pack(fill=BOTH,expand=1,side=BOTTOM)
		
#.........这里部分代码省略.........
开发者ID:elstupido,项目名称:rpg,代码行数:103,代码来源:rpg.py

示例13: Example

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class Example(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)

        self.parent = parent
        self.initUI()

    def initUI(self):
        self.username = ''
        self.r = praw.Reddit(USERAGENT)
        self.parent.title("")
        self.style = Style()
        self.style.theme_use("clam")
        self.pack(fill=BOTH, expand = 1)

        self.labelU = Label(self, text="U:")
        self.labelP = Label(self, text="P:")
        
        self.entryUsername = Entry(self)
        self.entryUsername.config(relief='flat')
        self.entryUsername.focus_set()
        self.entryUsername.bind('<Return>', lambda event: self.login(self.entryUsername.get()))
        self.entryUsername.bind('<Up>', lambda event: self.entryUsername.insert(0, self.username))

        self.quitbutton = Button(self, text="Quit", command= lambda: self.quit())
        self.quitbutton.config(width=6)
        
    
        self.labelKarma = Label(self, text = '•')
        self.labelKarma.grid(row = 3, column = 1)


        self.labelU.grid(row=0, column=0)
        self.entryUsername.grid(row=0, column=1)
        self.quitbutton.grid(row=2, column=1, pady=4)

        self.usernamelabel = Label(self, text='')
        self.usernamelabel.grid(row=1, column=1)


    def login(self, username):
        print('U: ' + username)
        self.username = username
        self.entryUsername.delete(0, 200)
        if username == '':
            self.entryUsername.focus_set()
            
        else:
            try:
                self.user = self.r.get_redditor(self.username)
                lkarma = str(self.user.link_karma)
                ckarma = str(self.user.comment_karma)
                lkarma = self.karmaRound(lkarma)
                ckarma = self.karmaRound(ckarma)
                karmastring = lkarma + ' • ' + ckarma
                self.labelKarma.config(text = karmastring)
                self.usernamelabel.config(text= self.username)

            except:
                self.labelKarma.config(text = '•')
                self.usernamelabel.config(text= 'User not found')
                pass

    def karmaRound(self, karma):
        if len(karma) > 4 and len(karma) < 7:
            tstring = karma[:-3]
            tstring2 = karma[-3:]
            karma = tstring + '.' + tstring2[:2] + 'K'
            return karma
        if len(karma) > 6:
            tstring = karma[:-6]
            tstring2 = karma[-6:]
            karma = tstring + '.' + tstring2[:2] + 'M'
            return karma
        else:
            return karma
开发者ID:Ortharn,项目名称:reddit,代码行数:78,代码来源:karmacount.py

示例14: GUI

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
class GUI(GetData):
    
    def __init__(self):
        super().__init__()
####################### initial interface #######################
        
        self.LabelName=['滴滿足點','弱關','中關','強關','高滿足點']
        self.BigThreeLabelName=['法人','自營商','投信','外資','三大法人']
        self.InTimeObject = InTimeData()
        self.InTimeObject.FutureInTime()
               
        self.interface = tkinter.Tk()
        self.interface.title("HI")
              
        self.aa=tkinter.Scrollbar()
        self.ThreemenBox=tkinter.Listbox(self.interface)
        self.ThreemenBox.grid(row=6,column=4)
        self.aa.config(command=self.ThreemenBox.yview())
        self.ThreemenBox.config(yscrollcommand=self.aa)

###############################################################################        
        self.inputPERatio = Label()
        self.inputPERatio["text"]="Input Ratio"
        self.inputPERatio.grid(row=0,column=0)
        self.inputPREField = Entry(self.interface)
        self.inputPREField.bind('<Return>',self.GetTextFromPREField)
        self.inputPREField.grid(row=0,column=1)
        
        self.inputEPS = Label()
        self.inputEPS["text"]="Input EPS"
        self.inputEPS.grid(row=1,column=0)
        self.inputEPSField = Entry(self.interface)
        self.inputEPSField.bind('<Return>',self.GetTextFromEPSField)
        self.inputEPSField.grid(row=1,column=1)
        
        self.inputVolume = Label()
        self.inputVolume["text"]="Input Volume"
        self.inputVolume.grid(row=2,column=0)
        self.inputVolumeField = Entry(self.interface)
        self.inputVolumeField.bind('<Return>',self.GetTextFromVolumeField)
        self.inputVolumeField.grid(row=2,column=1)
        
        self.inputWannaPrice = Label()
        self.inputWannaPrice["text"]="Input Close Price"
        self.inputWannaPrice.grid(row=3,column=0)
        self.inputWannaPriceField = Entry(self.interface)
        self.inputWannaPriceField.bind('<Return>',self.GetTextFromWannaPriceField)
        self.inputWannaPriceField.grid(row=3,column=1)
         
        self.CheckButton = tkinter.Button(text="Enter")
        self.CheckButton.bind('<Button-1>',self.tesfile)
        self.CheckButton.grid(row=4)
###############################################################################    
#期貨未平倉口數Label設定

        for x in range(0,5,1):
            self.InTimeFutureLabel = Label()  
            self.InTimeFutureLabel["text"]=self.BigThreeLabelName[x]
            self.InTimeFutureLabel.grid(row=x,column=4)

        self.FutureNameTitle=Label()
        self.FutureNameTitle["text"]="未平倉口數"
        self.FutureNameTitle.grid(row=0,column=5)
        self.FutureNameTitle=Label()
        self.FutureNameTitle["text"]="買賣超金額"
        self.FutureNameTitle.grid(row=0,column=6)
  
        self.HighSatisfy = StringVar()
        self.showWeakStage = StringVar()
        self.showPowerStage = StringVar()
        self.showMiddleStage=StringVar()
        self.LowSatisfy = StringVar()
        self.showClosePrice = StringVar()
        
        self.LabelLowSatisfy=Label()
        self.LabelLowSatisfy.grid(row=1,column=8)
        self.LabelWeak = Label()
        self.LabelWeak.grid(row=1,column=9)
        self.LabelMiddle = Label()
        self.LabelMiddle.grid(row=1,column=10)
        self.LabelPower = Label()
        self.LabelPower.grid(row=1,column=11)
        self.LabelHighSatisfy = Label()
        self.LabelHighSatisfy.grid(row=1,column=12)
        self.LabelClose = Label() 
        self.LabelClose.grid(row=3,column=10)
        
        self.test2 = StringVar()
        self.test1 = Label()
        self.test1.grid(row=10,column=10)
        self.FutureToday()
        
#############################################################

        for x in range(8,13,1):                         ###set the label name
            self.InTimeFutureLabel = Label()  
            self.InTimeFutureLabel["text"]=self.LabelName[x-8]
            self.InTimeFutureLabel.grid(row=0,column=x)

        self.ThreeMenDollar()
#.........这里部分代码省略.........
开发者ID:sheettrait,项目名称:Stock_Python,代码行数:103,代码来源:Main.py

示例15: blog_posts

# 需要导入模块: from tkinter import Entry [as 别名]
# 或者: from tkinter.Entry import bind [as 别名]
def blog_posts(root, info):

    def next_window():
        for blogger in info['bloggers']:
            info['blogpost'][blogger] = []
        if info['platforms'] == ['Blogs'] and [entry.get() for entry in entries] == ['', '', '', '', '', '', '', '', '', '', '', '', '']:
            for blogger in info['bloggers']:
                info['blogpost'][blogger].append(screenname_to_website(blogger))
        for entry in entries:

            if entry.get() and entry.get() not in info['blogpost'].values():
                info['blogpost'][process_link(entry.get(), info['bloggers'])].append(entry.get())

        print(info['blogpost'])
        third_window(root=root, info=info)

    def back(info=info):
        for blogger in info['bloggers']:
            info['blogpost'][blogger] = []
        for entry in entries:
            if entry.get() and entry.get() not in info['blogpost'].values():
                info['blogpost'][process_link(entry.get(), info['bloggers'])].append(entry.get())
        second_window(root=root, info=info)

    def active_next(*args):
        send.state(['!disabled', 'active'])

    c = ttk.Frame(root)
    c.grid(column=0, row=0, sticky=(N, W, E, S))

    root.grid_columnconfigure(0, weight=3)
    root.grid_rowconfigure(0, weight=3)

    send = ttk.Button(c, text='Next', command=next_window, default='active')  # ,state='disabled')
    send.grid(column=2, row=15, sticky=(E), pady=0, padx=2)

    close = ttk.Button(c, text='Back', command=back, default='active')
    close.grid(column=1, row=15, pady=0, padx=2)

    t1 = Entry(c, width=60)
    t1.grid(column=0, row=1, sticky=W, padx=(20, 70), pady=(30, 5))
    t1.bind("<Button-1>", active_next)
    t2 = Entry(c, width=60)
    t2.grid(column=0, row=2, sticky=W, padx=(20, 0), pady=(5, 5))
    t2.bind("<Button-1>", active_next)
    t3 = Entry(c, width=60)
    t3.grid(column=0, row=3, sticky=W, padx=(20, 0), pady=5)
    t3.bind("<Button-1>", active_next)
    t4 = Entry(c, width=60)
    t4.grid(column=0, row=4, sticky=W, padx=(20, 0), pady=5)
    t4.bind("<Button-1>", active_next)
    t5 = Entry(c, width=60)
    t5.grid(column=0, row=5, sticky=W, padx=(20, 0), pady=5)
    t5.bind("<Button-1>", active_next)
    t6 = Entry(c, width=60)
    t6.grid(column=0, row=7, sticky=W, padx=(20, 0), pady=5)
    t6.bind("<Button-1>", active_next)
    t7 = Entry(c, width=60)
    t7.grid(column=0, row=8, sticky=W, padx=(20, 0), pady=(5))
    t7.bind("<Button-1>", active_next)
    ct1 = Entry(c, width=60)
    ct1.grid(column=0, row=9, sticky=W, padx=(20, 0), pady=(5))
    ct1.bind("<Button-1>", active_next)
    ct2 = Entry(c, width=60)
    ct2.grid(column=0, row=10, sticky=W, padx=(20, 0), pady=(5))
    ct2.bind("<Button-1>", active_next)
    ct3 = Entry(c, width=60)
    ct3.grid(column=0, row=11, sticky=W, padx=(20, 0), pady=5)
    ct3.bind("<Button-1>", active_next)
    ct4 = Entry(c, width=60)
    ct4.grid(column=0, row=12, sticky=W, padx=(20, 0), pady=5)
    ct4.bind("<Button-1>", active_next)
    ct5 = Entry(c, width=60)
    ct5.grid(column=0, row=13, sticky=W, padx=(20, 0), pady=5)
    ct5.bind("<Button-1>", active_next)
    ct6 = Entry(c, width=60)
    ct6.grid(column=0, row=14, sticky=W, padx=(20, 0), pady=5)
    ct6.bind("<Button-1>", active_next)

    entries = [t1, t2, t3, t4, t5, t6, t7, ct1, ct2, ct3, ct4, ct5, ct6]

    if info['tags']:
        a = list(zip(entries, info['tags']))
        for tag in a:
            tag[0].insert(0, tag[1])
        active_next()

    if info['blogpost']:
        links = []
        for el in info['blogpost'].keys():
            for link in info['blogpost'][el]:
                links += link
        a = list(zip(entries, links))
        for link in a:
            link[0].insert(0, link[1])
        active_next()

    root.title('Enter Blog Posts URLs')
    root.geometry('800x550+440+200')
开发者ID:glebanatalia,项目名称:natappy,代码行数:101,代码来源:natappy_gui.py


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