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


Python Tk.bind方法代码示例

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


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

示例1: demo

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def demo():
    root = Tk()
    root.bind('<Control-q>', lambda e: root.destroy())

    table = Table(root, 'Word Synset Hypernym Hyponym'.split(),
                  column_weights=[0, 1, 1, 1], 
                  reprfunc=(lambda i,j,s: '  %s' % s))
    table.pack(expand=True, fill='both')

    from nltk.corpus import wordnet
    from nltk.corpus import brown
    for word, pos in sorted(set(brown.tagged_words()[:500])):
        if pos[0] != 'N': continue
        word = word.lower()
        for synset in wordnet.synsets(word):
            hyper = (synset.hypernyms()+[''])[0]
            hypo = (synset.hyponyms()+[''])[0]
            table.append([word,
                          getattr(synset, 'definition', '*none*'),
                          getattr(hyper, 'definition', '*none*'),
                          getattr(hypo, 'definition', '*none*')])

    table.columnconfig('Word', background='#afa')
    table.columnconfig('Synset', background='#efe')
    table.columnconfig('Hypernym', background='#fee')
    table.columnconfig('Hyponym', background='#ffe')
    for row in range(len(table)):
        for column in ('Hypernym', 'Hyponym'):
            if table[row, column] == '*none*':
                table.itemconfig(row, column, foreground='#666',
                                 selectforeground='#666')
    root.mainloop()
开发者ID:aboSamoor,项目名称:nltk,代码行数:34,代码来源:table.py

示例2: main

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def main():
    root = Tk()
    # w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    w, h = 960, 540
    # get value from arduino
    # ser = serial.Serial('/dev/tty.usbserial', 9600)
    pos = 0
    root.overrideredirect(1)
    root.focus_set()
    root.bind("<Escape>", lambda e: e.widget.quit())
    root.geometry("%dx%d+300+300" % (w, h))
    canvas = Canvas(root, width=w, height=h, background="black")
    rect0 = canvas.create_rectangle(w/2-75, h/2-20, w/2+75, h/2+20, fill="#05f", outline="#05f")
    rect1 = canvas.create_rectangle(w/2-20, h/2-75, w/2+20, h/2+75, fill="#05f", outline="#05f")
    canvas.pack() 
    
    while (True):
        # gets angle and moves accordingly
        # pos = ser.readline()
        canvas.move(rect0, 1, 0)
        canvas.move(rect1, 1, 0)
        root.update()
        root.after(30)
      
    app = App(root)
    time.sleep(0.5)
    root.mainloop()  
开发者ID:KTanous,项目名称:DriverHUD,代码行数:29,代码来源:SteeringIndicator.py

示例3: main

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def main():
    fileWords = open('wordList.txt')
    fileWords = fileWords.read()
    fileWords = fileWords.split()
    def clear():
        os.system('cls' if platform.system() == "Windows" else "clear")
        
    def whenClicked(*args):
        prefix = pattern.get()
        labelText.set("")
        for word in fileWords:
            if word.startswith(prefix):
                labelText.set(str(labelText.get())+'\n'+word)
    
        
        
    root = Tk()
    root.title('AutoComplete')
    ttk.Label(root, text='Enter search pattern').pack()
    pattern = StringVar()
    ttk.Entry(root, textvariable=pattern).pack()
    ttk.Button(root, text='Submit', command=whenClicked).pack()
    labelText = StringVar()
    ttk.Label(root, textvariable=labelText).pack()
    root.bind('<Return>', whenClicked)
    root.mainloop()
开发者ID:MiguelSOliveira,项目名称:Python-Projects,代码行数:28,代码来源:AutoComplete.py

示例4: talker

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def talker(): 
    motion = Twist()
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    root = Tk()
    root.geometry("750x300+500+-1000")
    root.bind('<Key>', onKeyPress)
    app = DronControll(root,pubControllDron,pubControllTakeoff,pubControllLanding,pubControllCamera)
    root.mainloop() 
开发者ID:chaycv,项目名称:bebop_controll,代码行数:11,代码来源:talker.py

示例5: main

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def main():
    global root
    # Populate the content
    populate_content()
    
    # Launch the GUI
    root = Tk()
    # Center the window
    center(root, (800, 800))
    app = MainFrame(root)
    root.bind('<Control-c>', root.quit)
    root.mainloop()
开发者ID:nshaud,项目名称:content-recommendation,代码行数:14,代码来源:content_recommendation.py

示例6: _init_ui

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
    def _init_ui(self):
        root = Tk()
        root.title("parakeet")
        root.bind("<FocusOut>", self.close)
        root.bind("<Escape>", self.close)

        text = Text(root)
        text.config(width=60, height=1)
        text.pack(side=LEFT, fill=Y)
        text.bind("<Return>", self.handle_query)
        text.focus_force()

        return root, text
开发者ID:efruchter,项目名称:parakeet,代码行数:15,代码来源:parakeet.py

示例7: __init__

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
class Display:
    def __init__(self, fps=FPS, width=WIDTH, height=HEIGHT,
        board_offset_bottom=BOARD_OFFSET_BOTTOM,
        board_width=BOARD_WIDTH,
        board_height=BOARD_HEIGHT):
        self.root=Tk()
        self.root.protocol("WM_DELETE_WINDOW", self.root.destroy)
        self.width = width
        self.height = height
        self.canvas=Canvas(self.root, bg="black",width=width,height=height)
        self.board_width = board_width
        self.board_height = board_height
        self.board_offset_bottom = board_offset_bottom
        self.canvas.pack()
        self.fps = fps
        self.controllers = []
        #For reset
        self.root.bind("<space>", lambda e:self.reset_all())
        self.root.bind("<Escape>", lambda e:self.root.destroy())
    def run(self):
        self.root.after(1000//self.fps, self.loop)
        try:
            self.root.mainloop()
        except KeyboardInterrupt:
            self.root.destroy()
    def loop(self):
        actions = [controller.get_action(self.model) for controller in self.controllers]
        self.model.update(1./self.fps, actions)
        self.draw()
        self.root.after(1000//self.fps, self.loop)
    def draw(self):
        self.canvas.delete('all')
        self.board = self.canvas.create_rectangle(
            self.model.x()-self.board_width/2,
            self.board_offset_bottom+self.height-self.board_height,
            self.model.x()+self.board_width/2,
            self.board_offset_bottom+self.height, fill="green")
        self.pendulum = self.canvas.create_line(
            self.model.x(),
            self.board_offset_bottom+self.height-self.board_height,
            self.model.x()+self.model.arm_length*math.sin(self.model.alpha()),
            self.board_offset_bottom+self.height-self.board_height-self.model.arm_length*math.cos(self.model.alpha()),
            fill="blue", width=20)
    def attach_model(self, model):
        self.model = model
        self.draw()
    def attach_controller(self, controller):
        self.controllers.append(controller)
    def reset_all(self):
        self.model.randomize()
开发者ID:evancchow,项目名称:polebalance,代码行数:52,代码来源:pendulum.py

示例8: quickentry

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def quickentry(labels, callback, title='', defaults=None):
    "Simple dialog from grabbing parameters from the user."

    if defaults is None:
        defaults = {}

    root = Tk()

    root.title(title)
    root['padx'] = 20
    root['pady'] = 10

    widgets = {}
    for label in labels:

        # Create a text frame to hold the text Label and the Entry widget
        f = Frame(root)

        #Create a Label in textFrame
        l = Label(f)
        l['text'] = label
        l['width'] = 10
        l.pack(side=LEFT)

        w = Entry(f)
        w['width'] = 20
        w.pack(side=LEFT)

        w.insert(0, defaults.get(label, ''))

        widgets[label] = w

        f.pack()

    def cb():
        callback({label: widgets[label].get().strip() for label in labels})

    Button(root, text="Quit", command=lambda root=root: root.destroy()).pack(side=RIGHT)
    Button(root, text='Submit', command=cb).pack(side=RIGHT)


    root.protocol("WM_DELETE_WINDOW", lambda root=root: root.destroy())

    print '[quickentry] running'
    root.bind("<Return>", lambda e: cb())
    root.bind("<Escape>", lambda e: root.destroy())
    root.mainloop()
    print '[quickentry] done'
    return root
开发者ID:timvieira,项目名称:viz,代码行数:51,代码来源:quickentry.py

示例9: run

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def run(): # Main function that triggers the rest of the game
    root = Tk() # Initializes a new root
    root.resizable(width = FALSE, height = FALSE) # The canvas is not resizable
    root.title("Boggle - Aayush Tekriwal - (15-112 Term Project)") # Title
    (width, height) = (1000,600) # Width and height of 
    canvas = Canvas(root, width = width, height = height)
    canvas.pack()
    root.canvas = canvas.canvas = canvas
    class Struct: pass
    canvas.data = Struct() # Struct stores all data for global access
    canvas.data.width = width
    canvas.data.height = height
    initGame(root, canvas) 
    #root.bind("<Button-1>", printCoords) # Unhash to help modify graphics
    root.bind("<space >", lambda event: getWord(canvas, event))
    root.bind("<Return>", lambda event: getWord(canvas, event))
    root.mainloop()
开发者ID:aayushtekriwal,项目名称:BoggleBash_15112_Term-Project_Aayush-Tekriwal,代码行数:19,代码来源:BoggleBash.py

示例10: demo3

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def demo3():
    from nltk import Production

    (S, VP, NP, PP, P, N, Name, V, Det) = nonterminals("S, VP, NP, PP, P, N, Name, V, Det")

    productions = (
        # Syntactic Productions
        Production(S, [NP, VP]),
        Production(NP, [Det, N]),
        Production(NP, [NP, PP]),
        Production(VP, [VP, PP]),
        Production(VP, [V, NP, PP]),
        Production(VP, [V, NP]),
        Production(PP, [P, NP]),
        Production(PP, []),
        Production(PP, ["up", "over", NP]),
        # Lexical Productions
        Production(NP, ["I"]),
        Production(Det, ["the"]),
        Production(Det, ["a"]),
        Production(N, ["man"]),
        Production(V, ["saw"]),
        Production(P, ["in"]),
        Production(P, ["with"]),
        Production(N, ["park"]),
        Production(N, ["dog"]),
        Production(N, ["statue"]),
        Production(Det, ["my"]),
    )

    t = Tk()

    def destroy(e, t=t):
        t.destroy()

    t.bind("q", destroy)
    p = ProductionList(t, productions)
    p.pack(expand=1, fill="both")
    p.add_callback("select", p.markonly)
    p.add_callback("move", p.markonly)
    p.focus()
    p.mark(productions[2])
    p.mark(productions[8])
开发者ID:Jaemu,项目名称:haiku.py,代码行数:45,代码来源:cfg.py

示例11: prompt_gui

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
    def prompt_gui(self, name, propagate_exception = False):
        ''' Returns None if failed to load tkinter or open display.
        (unless propagate_exception == True).'''
        
        ''' I thought about caching and reusing the tkinter instance, but it might be hard
        to properly temporarily exit from mainloop and suspend the application.
        Anyway, it takes like 10ms to restart it.'''
        try:
            from Tkinter import Tk, Label, Frame, Entry, StringVar
            root = Tk()
        except:
            if propagate_exception:
                raise
            return None

        root.title('Enter value for \'%s\':' % name)
        frame = Frame(root)
        frame.pack(fill = 'y', expand = True)

        label = Label(frame, text='Enter value for \'%s\':' % name)
        label.pack(side='left')
        
        var = StringVar()
        entry = Entry(frame, textvariable = var)
        entry.pack(side='left')
        
        result = []
        root.bind('<Return>', lambda ev: (result.append(var.get()), root.destroy()))
        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()
        root.geometry('+%d+%d' % (ws * 0.4, hs * 0.4))
        entry.focus()
        
        # If I don't do this then for some reason the window doesn't get focus
        # on the second and following invocations. 
        root.focus_force()

        root.mainloop()
        if not len(result):
            # mimic the behaviour of CLI version
            raise KeyboardInterrupt()
        return result[0]
开发者ID:Vlad-Shcherbina,项目名称:icfpc2013-follow-up,代码行数:44,代码来源:simple_settings.py

示例12: _init_ui

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
    def _init_ui(self):
        root = Tk()
        root.title("pylens")
        root.bind("<FocusOut>", self.close)
        root.bind("<Escape>", self.close)

        # center the window
        root.withdraw()
        root.update_idletasks()  # Update "requested size" from geometry manager
        x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
        y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
        root.geometry("+%d+%d" % (x, y))
        root.deiconify()

        text = Text(root)
        text.config(width=60, height=1)
        text.pack(side=LEFT, fill=Y)
        text.bind("<Return>", self.handle_query)
        text.focus_force()

        return root, text
开发者ID:patricklucas,项目名称:pylens,代码行数:23,代码来源:pylens.py

示例13: main

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def main():
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option('-W', '--width',  type='int', default=300)
    parser.add_option('-H', '--height', type='int', default=300)
    parser.add_option('-c', '--center', type='complex', default=0+0j)
    parser.add_option('-s', '--side',   type='float', default=4)
    (options, args) = parser.parse_args()

    root = Tk()
    l = Label(root)
    l.pack()

    W, H = options.width, options.height
    center, side = options.center, options.side

    im = Image.new('P', (W, H), 0)
    im.putpalette([randrange(256) for n in range(3 * 256)])
    p = im.load()
    
    z = z_converter(W, H, center, side)
    l.pim = PhotoImage(im)
    l.config(image=l.pim)

    def paint_column(x):
        if x % 10 == 0: print "Column %d" % x
        for y in range(H):
            p[x, y] = pixel(z(x, y))
        l.pim = PhotoImage(im)
        l.config(image=l.pim)

        if x + 1 < W:
            root.after(1, paint_column, x + 1)

    def start(event):
        root.after(1, paint_column, 0)

    root.bind('<FocusIn>', start)
    root.mainloop()
开发者ID:rbonvall,项目名称:mandelbrot,代码行数:41,代码来源:mandelbrot.py

示例14: demo

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def demo():
    root = Tk()
    root.bind("<Control-q>", lambda e: root.destroy())

    table = Table(
        root, "Word Synset Hypernym Hyponym".split(), column_weights=[0, 1, 1, 1], reprfunc=(lambda i, j, s: "  %s" % s)
    )
    table.pack(expand=True, fill="both")

    from nltk.corpus import wordnet
    from nltk.corpus import brown

    for word, pos in sorted(set(brown.tagged_words()[:500])):
        if pos[0] != "N":
            continue
        word = word.lower()
        for synset in wordnet.synsets(word):
            hyper = (synset.hypernyms() + [""])[0]
            hypo = (synset.hyponyms() + [""])[0]
            table.append(
                [
                    word,
                    getattr(synset, "definition", "*none*"),
                    getattr(hyper, "definition", "*none*"),
                    getattr(hypo, "definition", "*none*"),
                ]
            )

    table.columnconfig("Word", background="#afa")
    table.columnconfig("Synset", background="#efe")
    table.columnconfig("Hypernym", background="#fee")
    table.columnconfig("Hyponym", background="#ffe")
    for row in range(len(table)):
        for column in ("Hypernym", "Hyponym"):
            if table[row, column] == "*none*":
                table.itemconfig(row, column, foreground="#666", selectforeground="#666")
    root.mainloop()
开发者ID:Joselin,项目名称:nltk,代码行数:39,代码来源:table.py

示例15: demo3

# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import bind [as 别名]
def demo3():
    from nltk import Production
    (S, VP, NP, PP, P, N, Name, V, Det) = \
        nonterminals('S, VP, NP, PP, P, N, Name, V, Det')
    
    productions = (
        # Syntactic Productions
        Production(S, [NP, VP]),
        Production(NP, [Det, N]),
        Production(NP, [NP, PP]),
        Production(VP, [VP, PP]),
        Production(VP, [V, NP, PP]),
        Production(VP, [V, NP]),
        Production(PP, [P, NP]),
        Production(PP, []),

        Production(PP, ['up', 'over', NP]),
        
        # Lexical Productions
        Production(NP, ['I']),   Production(Det, ['the']),
        Production(Det, ['a']),  Production(N, ['man']),
        Production(V, ['saw']),  Production(P, ['in']),
        Production(P, ['with']), Production(N, ['park']),
        Production(N, ['dog']),  Production(N, ['statue']),
        Production(Det, ['my']),
        )
    
    t = Tk()
    def destroy(e, t=t): t.destroy()
    t.bind('q', destroy)
    p = ProductionList(t, productions)
    p.pack(expand=1, fill='both')
    p.add_callback('select', p.markonly)
    p.add_callback('move', p.markonly)
    p.focus()
    p.mark(productions[2])
    p.mark(productions[8])
开发者ID:gijs,项目名称:nltk,代码行数:39,代码来源:cfg.py


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