<small id='RKyyG'></small><noframes id='RKyyG'>

  • <i id='RKyyG'><tr id='RKyyG'><dt id='RKyyG'><q id='RKyyG'><span id='RKyyG'><b id='RKyyG'><form id='RKyyG'><ins id='RKyyG'></ins><ul id='RKyyG'></ul><sub id='RKyyG'></sub></form><legend id='RKyyG'></legend><bdo id='RKyyG'><pre id='RKyyG'><center id='RKyyG'></center></pre></bdo></b><th id='RKyyG'></th></span></q></dt></tr></i><div id='RKyyG'><tfoot id='RKyyG'></tfoot><dl id='RKyyG'><fieldset id='RKyyG'></fieldset></dl></div>
    <legend id='RKyyG'><style id='RKyyG'><dir id='RKyyG'><q id='RKyyG'></q></dir></style></legend>
    • <bdo id='RKyyG'></bdo><ul id='RKyyG'></ul>

    <tfoot id='RKyyG'></tfoot>

        Python Tkinter 菜单命令不起作用

        Python Tkinter Menu Command Not Working(Python Tkinter 菜单命令不起作用)
          <bdo id='tknvV'></bdo><ul id='tknvV'></ul>
          <legend id='tknvV'><style id='tknvV'><dir id='tknvV'><q id='tknvV'></q></dir></style></legend>
                <tbody id='tknvV'></tbody>

            • <tfoot id='tknvV'></tfoot>

                  <i id='tknvV'><tr id='tknvV'><dt id='tknvV'><q id='tknvV'><span id='tknvV'><b id='tknvV'><form id='tknvV'><ins id='tknvV'></ins><ul id='tknvV'></ul><sub id='tknvV'></sub></form><legend id='tknvV'></legend><bdo id='tknvV'><pre id='tknvV'><center id='tknvV'></center></pre></bdo></b><th id='tknvV'></th></span></q></dt></tr></i><div id='tknvV'><tfoot id='tknvV'></tfoot><dl id='tknvV'><fieldset id='tknvV'></fieldset></dl></div>
                1. <small id='tknvV'></small><noframes id='tknvV'>

                  本文介绍了Python Tkinter 菜单命令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Python 2.6.5 中执行以下代码.我想要做的是显示一个带有应用程序"菜单的主窗口.我希望菜单有一系列命令,这些命令应该对应于 Apps 字典的键.当我单击该命令时,我希望默认 Web 浏览器打开并导航到该特定键的 Apps 字典中的 url.相反,当我执行代码时,浏览器将打开到 Apps 字典中的第一个 url,而无需任何点击.请帮忙!

                  I am trying to execute the following code in Python 2.6.5. What I want to do is show a main window with an 'Applications' menu. I want the menu to have a series of commands which should correspond to the keys of the Apps dictionary. When I click the command, I would like the default web browser to open and navigate to the url in the Apps dictionary for that particular key. Instead, when I execute the code the browser is opening to the first url in the Apps dictionary without any clicking. Help please!

                  from Tkinter import *
                  import webbrowser
                  
                  #Real links are to pages on Intranet.
                  Apps={
                       'Google':'http://www.google.com/',
                       'Yahoo':'http://www.yahoo.com/'
                       }
                  
                  def openApp(appURL):
                       webbrowser.open(appURL, new=1, autoraise=1)
                       return None
                  
                  root=Tk()
                  menubar=Menu(root)
                  root.config(menu=menubar)
                  appsMenu=Menu(menubar)
                  for app in Apps:
                       appsMenu.add_command(label=app, command=openApp(Apps[app]))
                  menubar.add_cascade(label='Apps', menu=appsMenu)
                  root.mainloop()
                  

                  推荐答案

                   appsMenu.add_command(label=app, command=openApp(Apps[app]))
                  

                  调用函数的命令参数需要包装在 lambda 中,以防止它们被立即调用.此外,在 for 循环中绑定的命令需要循环变量作为默认参数,以便每次都绑定正确的值.

                  Command parameters that call functions need to be wrapped in a lambda, to prevent them from being called right away. Additionally, commands bound within a for loop need the looping variable as a default argument, in order for it to bind the right value each time.

                   appsMenu.add_command(label=app, command=lambda app=app: openApp(Apps[app]))
                  

                  这篇关于Python Tkinter 菜单命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                    <small id='xCRYf'></small><noframes id='xCRYf'>

                      <tbody id='xCRYf'></tbody>
                    <i id='xCRYf'><tr id='xCRYf'><dt id='xCRYf'><q id='xCRYf'><span id='xCRYf'><b id='xCRYf'><form id='xCRYf'><ins id='xCRYf'></ins><ul id='xCRYf'></ul><sub id='xCRYf'></sub></form><legend id='xCRYf'></legend><bdo id='xCRYf'><pre id='xCRYf'><center id='xCRYf'></center></pre></bdo></b><th id='xCRYf'></th></span></q></dt></tr></i><div id='xCRYf'><tfoot id='xCRYf'></tfoot><dl id='xCRYf'><fieldset id='xCRYf'></fieldset></dl></div>

                    1. <tfoot id='xCRYf'></tfoot>

                        • <bdo id='xCRYf'></bdo><ul id='xCRYf'></ul>
                            <legend id='xCRYf'><style id='xCRYf'><dir id='xCRYf'><q id='xCRYf'></q></dir></style></legend>