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


Python Entry.bind方法代码示例

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


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

示例1: DateWidget

# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import bind [as 别名]
 class DateWidget(Frame):
     """Gets a date from the user."""
     def __init__(self, master):
         """Make boxes, register callbacks etc."""
         Frame.__init__(self, master)
         self.label = Label(self, text="När är du född?")
         self.label.pack()
         self.entry_text = StringVar()
         self.entry_text.trace("w", lambda *args: self.onEntryChanged())
         self.entry = Entry(self, width=date_entry_width,
              textvariable=self.entry_text)
         self.entry.insert(0, "ÅÅÅÅ-MM-DD")
         self.entry.pack(pady=small_pad)
         self.button = Button(self, text="Uppdatera",
              command=lambda: self.onDateChanged())
         self.button.pack()
         self.entry.focus_set()
         self.entry.select_range(0, END)
         self.entry.bind("<Return>", lambda x: self.onDateChanged())
     def setListener(self, pred_view):
         """Select whom to notify when a new date is entered."""
         self.pred_view = pred_view
     def onDateChanged(self):
         """Notifies the PredictionWidget that the date has been changed."""
         try:
             date = datetime.datetime.strptime(self.entry.get(),
                  "%Y-%m-%d").date()
             self.pred_view.update(date)
         except ValueError:
             self.entry.configure(foreground="red")
     def onEntryChanged(self):
         """Reset the text color."""
         self.entry.configure(foreground="")
开发者ID:JoelSjogren,项目名称:horoskop,代码行数:35,代码来源:main.py

示例2: _gui

# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import bind [as 别名]
def _gui():
  try:
    from tkinter import Tk, ttk, filedialog, messagebox, StringVar, IntVar
    from tkinter.ttk import Button, Entry, Frame, Label, LabelFrame, Notebook, Radiobutton, Style
  except:
    sys.exit("Unable to load tkinter. Aborting.")
  
  def _check_single(): #check the input and accordingly give the output... for the f_single tab
    if txt_f_single_entry.get()=="":
      lbl_f_single_result.config(text="", style="TLabel")
    elif check_afm(txt_f_single_entry.get()):
      lbl_f_single_result.config(text="Έγκυρο ΑΦΜ.", style="valid.TLabel")
    else:
      lbl_f_single_result.config(text="Άκυρο ΑΦΜ.", style="invalid.TLabel")
  
  def _select_input_file():
    strv_f_file_input.set(filedialog.askopenfilename(title="Άνοιγμα αρχείου"))
    if strv_f_file_input.get() != "" and strv_f_file_output.get() != "":
      btn_f_file_submit.config(state="normal")
    else: btn_f_file_submit.config(state="disabled")
#TODO a much better mechanism to enable / disable btn_f_file_submit is needed.
  def _select_output_file():
    strv_f_file_output.set(filedialog.asksaveasfilename(title="Αποθήκευση ως..."))
    if strv_f_file_input.get() != "" and strv_f_file_output.get() != "":
      btn_f_file_submit.config(state="normal")
    else: btn_f_file_submit.config(state="disabled")
  
  def _check_file():#TODO this could / should be merged with the TUI version...
    input_filepath = strv_f_file_input.get()
    output_filepath = strv_f_file_output.get()
    filter_output = intvar_filter_sel.get()
    try:
      input_file = open(input_filepath, "r")
      output_file = open(output_filepath, "w")
    except:
      messagebox.showerror(title="Σφάλμα", message="Αδυναμία διαχείρησης των αρχείων που ορίσατε.\n\nΠαρακαλώ επιβεβαιώστε πως το αρχείο με τα δεδομένα υπάρχει, πως έχετε δικαιώματα ανάγνωσης, και πως έχετε δικαιώματα εγγραφής στον κατάλογο εξαγωγής των αποτελεσμάτων.")
      return
    counter = {True:0, False:0}
    for entry in input_file:
      validation = check_afm(entry.strip())
      counter[validation]+=1
      if filter_output == 3 and validation == False:
        output_file.write(entry)
      elif filter_output == 2 and validation == True:
        output_file.write(entry)
      elif filter_output == 1:
        output_file.write(entry.strip() + "\t" + str(validation) + "\n\r")
    lbl_f_file_result.config(text="Σύνολο: "+str(counter[True]+counter[False])+"\nΈγκυρα: "+str(counter[True])+"\nΆκυρα: "+str(counter[False]))

  #create the window
  main_window = Tk()
  main_window.title("Έλεγχος εγκυρότητας Α.Φ.Μ. (v 2.0)")
  main_window.geometry("600x180")
  main_window.minsize(600,180)

  #fool arround with styling
  style = ttk.Style()
  style.configure("valid.TLabel", background="green")
  style.configure("empty.TLabel", background="white")
  style.configure("invalid.TLabel", background="red")
  style.configure("TNotebook", padding = 10)
  
  #create the Notebook
  tabs = Notebook(main_window)
  f_single = Frame(tabs)
  f_file = Frame(tabs)
  tabs.add(f_single, text="Μεμονομένα Α.Φ.Μ.")
  tabs.add(f_file, text="Λίστα από αρχείο")#add state="disabled" prior to git push until ready
  tabs.pack(anchor="nw")
  
  #add some widgets in f_single tab
  lbl_f_single_instructions = Label(f_single, text="Εισάγετε έναν ΑΦΜ για έλεγχο")
  lbl_f_single_instructions.grid(column=0, row=0)

  lbl_f_single_result = Label(f_single, text="", width=10, justify="center")
  lbl_f_single_result.grid(column=1, row=0, rowspan=2, sticky="ewns")

  txt_f_single_entry = Entry(f_single, width=11)
  txt_f_single_entry.focus()
  txt_f_single_entry.bind("<KeyRelease>", lambda e: _check_single() )
  txt_f_single_entry.grid(column=0,row=1)

  #btn_f_single_submit = Button(f_single, text="Έλεγχος", command=_check_single)
  #btn_f_single_submit.grid(column=0,row=2)
    
  #add some widgets in f_file tab
  lbl_f_file_finput = Label(f_file, text="Άνοιγμα...")
  lbl_f_file_finput.grid(column=0, row=0)
  strv_f_file_input = StringVar()
  txt_f_file_finput = Entry(f_file, textvariable = strv_f_file_input)
  txt_f_file_finput.grid(column=1, row=0)
  btn_f_file_finput = Button(f_file, text="...", width=3, command=_select_input_file)
  btn_f_file_finput.grid(column=2, row=0, sticky="W")
  
  lbl_f_file_foutput = Label(f_file, text="Αποθήκευση ως...")
  lbl_f_file_foutput.grid(column=0, row=1)
  strv_f_file_output = StringVar()
  txt_f_file_foutput = Entry(f_file, textvariable = strv_f_file_output)
  txt_f_file_foutput.grid(column=1, row=1)
  btn_f_file_foutput = Button(f_file, text="...", width=3, command=_select_output_file)
#.........这里部分代码省略.........
开发者ID:C-Makridis,项目名称:check_AFM,代码行数:103,代码来源:checkAFM.py

示例3: MemberChecker

# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import bind [as 别名]
class MemberChecker(PanedWindow):
    def __init__(self, parent):
        PanedWindow.__init__(self, parent, background="white")

        self.parent = parent
        self.init_data()
        self.init_log()
        self.init_ui()
        self.update_status()

    def init_data(self):
        self.data_store = api.DataStore()

    def init_log(self):
        self.entrance_log = entrance_log.EntranceLog()

    def init_ui(self):
        self.parent.title("Member Checker")
        self.columnconfigure(3, weight=3)
        self.pack(fill=BOTH, expand=True)

        self.input = StringVar()
        self.input_entry = Entry(self, textvariable=self.input)
        self.input_entry.bind('<Return>', self.submit)
        self.input_entry.grid(row=0, column=0, columnspan=3, sticky=E + W)

        self.result = StringVar()
        self.result_label = Label(self, textvariable=self.result)
        self.result_label.grid(row=3, column=0, columnspan=3, sticky=E + W)

        self.name = StringVar()
        name_label = Label(self, textvariable=self.name)
        name_label.grid(row=2, column=0, columnspan=3, sticky=E + W)

        self.status = StringVar()
        status_label = Label(self, textvariable=self.status)
        status_label.grid(row=4, column=0, columnspan=4, sticky=E + W)

        submit_button = Button(self, text="Submit", command=self.submit)
        submit_button.grid(row=1, column=2)

        enter_without_card_button = Button(self, text="Enter without card", command=self.enter_without_card)
        enter_without_card_button.grid(row=1, column=0)

        enter_member_without_card_button = Button(self, text="Enter member without card",
                                                  command=self.enter_member_without_card)
        enter_member_without_card_button.grid(row=1, column=1)

        self.entrance_log_list = Listbox(self)
        self.entrance_log_list.grid(row=0, column=3, rowspan=4, sticky=E + W + S + N)

        self.input_entry.focus()

    def load_data(self):
        if messagebox.askyesno("Load new API Data",
                               "Are you sure you want to load the new API data? All previous data will be removed. The program might be unresponsive for a few seconds, but don't kill it, please! It has feelings too."):
            self.data_store.load_api_data()

    def enter_by_identification(self, identification):
        member = self.data_store.find_member_by_identification(identification)
        if member is None:
            if messagebox.askyesno("Not a member",
                                   "This university identification is not registered as a member. Do you want to let them in as a non-member?"):
                self.enter_non_member_by_identification(identification)
        else:
            self.enter_member(member)

    def enter_by_barcode(self, barcode):
        member = self.data_store.find_member_by_barcode(barcode)
        if member is None:
            if messagebox.askyesno("Not a member",
                                   "This barcode is not registered as a member. Do you want to let them in as a non-member?"):
                self.enter_non_member_by_barcode(barcode)
        else:
            self.enter_member(member)

    def enter_non_member_by_identification(self, identification):
        self.entrance_log.enter_non_member_by_identification(identification)
        self.enter_non_member()

    def enter_non_member_by_barcode(self, barcode):
        self.entrance_log.enter_non_member_by_barcode(barcode)
        self.enter_non_member()

    def enter_without_card(self):
        self.clear_result()
        self.entrance_log.enter_without_card()
        self.enter_non_member()
        self.input_entry.focus()

    def enter_member(self, member):
        inside_result = self.entrance_log.is_member_inside(member)
        if inside_result[0]:
            if not messagebox.askyesno("Already inside",
                                       "This membership card has already been used to enter at {}. Are you sure you want to register it again? Normally you should let this person enter without card (and bill them accordingly).".format(
                                           inside_result[1])):
                return
        self.entrance_log.enter_member(member)
        self.result.set('Member!')
        self.result_label.configure(background='green')
#.........这里部分代码省略.........
开发者ID:FKint,项目名称:LitusMemberChecker,代码行数:103,代码来源:__init__.py

示例4: __init__

# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import bind [as 别名]
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.player = StringVar()
        self.character = StringVar()
        self.dm = StringVar()
        self.str = StringVar()
        self.int = StringVar()
        self.wis = StringVar()
        self.dex = StringVar()
        self.con = StringVar()
        self.cha = StringVar()
        self.JPpoison = StringVar()
        self.JPwands = StringVar()
        self.JPparalysis = StringVar()
        self.JPbreath = StringVar()
        self.JPspell = StringVar()
        self.class_ = StringVar()
        self.race = StringVar()
        self.align = StringVar()
        self.AC = StringVar()
        self.HP = StringVar()
        self.maxHP = StringVar()
        self.XP_to_add = StringVar()
        self.XPbonus = StringVar()
        self.XPtotal = IntVar()
        self.level = StringVar()

        self.init_once()

        (
            self.baseXP,
            self.mainCarRace,
            self.mainCarClass) = self.classDifferenciation()
        self.remainingXP = StringVar()
        self.remainingXP.set(self.getRemainingXP())
        self.bonusXP = StringVar()
        self.bonusXP.set(self.getBonusXP())

        self.freeze = IntVar()
        self.freeze.set(1)

        Label(self, text="Player Name:").grid(row=0, column=0, columnspan=2)
        Label(self, text="Character Name :").grid(
            row=0, column=4, columnspan=2)
        Label(self, text="DM Name:").grid(row=0, column=8, columnspan=2)
        Label(self, text="STR:").grid(row=1, column=0)
        Label(self, text="INT:").grid(row=2, column=0)
        Label(self, text="WIS:").grid(row=3, column=0)
        Label(self, text="DEX:").grid(row=4, column=0)
        Label(self, text="CON:").grid(row=5, column=0)
        Label(self, text="CHA:").grid(row=6, column=0)
        Label(self, text="Poison/Deathray:").grid(row=1, column=2)
        Label(self, text="Wands:").grid(row=2, column=2)
        Label(self, text="Paralysis:").grid(row=3, column=2)
        Label(self, text="Dragon Breath:").grid(row=4, column=2)
        Label(self, text="Spells:").grid(row=5, column=2)
        Label(self, text="Armor Class").grid(row=1, column=4, columnspan=1)
        Label(self, text="Health Points").grid(row=1, column=5, columnspan=3)
        Label(self, text="  /  ").grid(row=2, column=6)
        Label(self, text="Class :").grid(row=3, column=4)
        Label(self, text="Race :").grid(row=4, column=4)
        Label(self, text="XP to add :").grid(row=7, column=0)
        Label(self, text="Remaining :").grid(row=8, column=0)
        Label(self, text="Bonus :").grid(row=7, column=2)
        Label(self, text="Alignment :").grid(row=3, column=6)
        Label(self, text="Level :").grid(row=9, column=0, columnspan=2)
        self.remainingLabel = Label(
            self,
            textvariable=self.remainingXP,
            relief=SUNKEN,
            width=5)
        self.remainingLabel.grid(row=8, column=1)
        self.bonusLabel = Label(
            self,
            textvariable=self.bonusXP,
            relief=SUNKEN,
            width=5)
        self.bonusLabel.grid(row=7, column=3)
        self.levelLabel = Label(
            self,
            textvariable=self.level,
            relief=SUNKEN,
            width=5)
        self.levelLabel.grid(row=9, column=2, columnspan=2)

        Eplayer = Entry(self, textvariable=self.player)
        Eplayer.grid(row=0, column=2, columnspan=2)
        Eplayer.bind(sequence='<KeyRelease>', func=self.refresh)

        Echaracter = Entry(self, textvariable=self.character)
        Echaracter.grid(row=0, column=6, columnspan=2)
        Echaracter.bind(sequence='<KeyRelease>', func=self.refresh)

        EDM = Entry(self, textvariable=self.dm)
        EDM.grid(row=0, column=10, columnspan=2)
        EDM.bind(sequence='<KeyRelease>', func=self.refresh)

        Estr = Entry(self, textvariable=self.str)
        Estr.grid(row=1, column=1)
        Estr.bind(sequence='<KeyRelease>', func=self.refresh)
#.........这里部分代码省略.........
开发者ID:jkesselring,项目名称:DnDApp,代码行数:103,代码来源:character.py

示例5: __init__

# 需要导入模块: from tkinter.ttk import Entry [as 别名]
# 或者: from tkinter.ttk.Entry import bind [as 别名]
class SettingsUI:
    
    def __init__(self, mainFrame):
        "initiates settings and creates the interface"
        self.playerList = []
        self.gameList = ("301", "501", "Clock")
        self.initUI(mainFrame)
        
    
    def buildPlayerHeaderString(self):
        """Build a connection string from a dictionary of parameters.
    
        Returns string."""
        return "Players: " + ", ".join(["%s" % player.name for player in self.playerList])
    
    def addPlayerText(self, name):
        self.playerList.append(Player(name))
        
        #bind add player click event
    def onAddPlayerClick(self, event):
        "callback method for the add player button"
        self.addPlayer()
    
    def onAddPlayerEnter(self, event):
        "callback method for the add player button"
        if event.keycode == 13:
            self.addPlayer()
            
    def addPlayer(self):
        name = self.playerNameEntry.get()
        if name:
            self.addPlayerText(name)
            self.playerString.set(self.buildPlayerHeaderString())
            self.nameFieldVar.set("")
            self.playerNameEntry.focus()
        return("break")
     
    def initUI(self, mainFrame):
        """initialize the User Interface"""
        
        # styles
        style = Style()
        style.configure("GRN.TLabel", background="#ACF059")
        style.configure("GRN.TFrame", background="#ACF059")
        style.configure("BLK.TFrame", background="#595959")
        
        
        # create top frame
        topFrame = Frame(mainFrame, style="GRN.TFrame", padding=8)
        topFrame.pack(fill=BOTH, side=TOP)
        
        # create black border
        borderFrame = Frame(mainFrame, style="BLK.TFrame")
        borderFrame.pack(fill=BOTH, side=TOP)
        
        # create add player frame
        addPlayerFrame = Frame(mainFrame, padding=8)
        addPlayerFrame.pack(side=TOP)
        
        # create text field for add button
        self.nameFieldVar = StringVar()
        self.playerNameEntry = Entry(addPlayerFrame, textvariable = self.nameFieldVar)
        self.playerNameEntry.pack(side=LEFT)
        # create add player button
        addButton = Button(addPlayerFrame, text="Add player")
        addButton.pack(side=LEFT)
        
        # create choose game list
        self.currentGame = StringVar()
        self.currentGame.set(self.gameList[0])
        gameDropDown = OptionMenu(mainFrame, self.currentGame, self.gameList[0], *self.gameList)
        gameDropDown.pack(side=TOP)

        # create start game button
        startGameButton = Button(mainFrame, text="Start")
        
        startGameButton.bind("<Button-1>", self.startGame)
        startGameButton.pack(side=TOP)
        
        # create label and set text
        self.playerString = StringVar()
        self.playerString.set(self.buildPlayerHeaderString())
        headerLabel = Label(topFrame, textvariable=self.playerString, style="GRN.TLabel")
        headerLabel.pack(side=TOP)     
        addButton.bind("<Button-1>", self.onAddPlayerClick)
        self.playerNameEntry.bind("<Key>", self.onAddPlayerEnter)
        
        #set focus
        self.playerNameEntry.focus()
        
    def startGame(self,event):
        "starts the selected game"
        if self.playerList:
            mainFrame.pack_forget()
            gameFrame = Frame(root)
            gameFrame.pack(fill=BOTH, expand=1)
                
            game = self.currentGame.get()
            if game == "301":
                gameX01.GameX01(gameFrame, self.playerList)
#.........这里部分代码省略.........
开发者ID:fi-ka,项目名称:DartScore,代码行数:103,代码来源:ui.py


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