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

    <legend id='71JCa'><style id='71JCa'><dir id='71JCa'><q id='71JCa'></q></dir></style></legend>

        • <bdo id='71JCa'></bdo><ul id='71JCa'></ul>

      1. <tfoot id='71JCa'></tfoot>

        <small id='71JCa'></small><noframes id='71JCa'>

      2. 如何将 Tkinter destroy() 绑定到 Debian 中的一个键?

        How to bind Tkinter destroy() to a key in Debian?(如何将 Tkinter destroy() 绑定到 Debian 中的一个键?)
          <bdo id='U5YFf'></bdo><ul id='U5YFf'></ul>

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

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

                    <tbody id='U5YFf'></tbody>
                  本文介绍了如何将 Tkinter destroy() 绑定到 Debian 中的一个键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下代码在 MS Windows 中正常工作(按 q 时脚本退出):

                  The following code works correctly in MS Windows (the script exits when pressing q):

                  import Tkinter as tk
                  
                  class App():
                      def __init__(self):
                          self.root = tk.Tk()
                          self.root.geometry("{0}x{1}+0+0".format(
                              self.root.winfo_screenwidth(), self.root.winfo_screenheight())
                          )
                          self.root.overrideredirect(True)
                          tk.Label(text="some text here").grid()
                          self.root.bind('q', self.appexit)
                          self.root.mainloop()
                  
                      def appexit(self, event):
                          self.root.destroy()
                  
                  App()
                  

                  我尝试在无窗口管理器"的 Debian 环境中运行它(启动到控制台,运行 startx,它通过 .xinitrc 启动脚本(唯一的命令在那里)).

                  I tried to run it in a "window manager-less" Debian environment (boot to console, run startx, which launches the script via .xinitrc (the only command there)).

                  脚本按预期启动,但按 q 不会执行任何操作(我希望 X 关闭并返回文本控制台).我后来尝试在 mainloop() 之前添加以防万一 self.root.focus() 但它没有帮助.

                  The script starts as expected but pressing q does not do anything (I was expecting X to close and return to the text console). I later tried to add just in case self.root.focus() before the mainloop() but it did not help.

                  MS Windows 和 Debian 环境之间出现这种不同行为的原因可能是什么?

                  What could be the reason of this different behavior between the MS Windows and Debian environment?

                  推荐答案

                  With overrideredirect 程序失去了与窗口管理的连接,因此它似乎无法获取有关按下的按键的信息,甚至无法聚焦.

                  With overrideredirect program loses connection with window manage so it seems that it can't get information about pressed keys and even it can't be focused.

                  MS Windows 是一个大窗口管理器,所以 overrideredirect 似乎在那个系统上不起作用.

                  MS Windows is one big window manager so it seems that overrideredirect doesn't work on that system.

                  也许你可以使用 self.root.attributes('-fullscreen', True) 代替 self.root.overrideredirect(True)

                  Maybe you could use self.root.attributes('-fullscreen', True) in place of self.root.overrideredirect(True)

                  顺便说一句:为了测试我使用 self.root.after(5000, self.root.destroy) - 当我无法控制它时在 5 秒后杀死窗口.

                  BTW: for testing I use self.root.after(5000, self.root.destroy) - to kill window after 5s when I can't control it.

                  fullscreen 的一些(工作)示例.

                  Some (working) example with fullscreen.

                  在 Linux 程序上使用 overrideredirect 可以获得键盘事件,因此绑定不起作用,并且您无法聚焦 Entry().但是鼠标和 Button() 可以工作.overrideredirect 适用于带或不带按钮的启动画面".

                  With overrideredirect on Linux program can get keyboard events so binding doesn't work, and you can't focus Entry(). But mouse and Button() works. overrideredirect is good for "splash screen" with or without buttons.

                  import Tkinter as tk
                  
                  class App():
                      def __init__(self):
                          self.root = tk.Tk()
                  
                          # this works
                  
                          self.root.attributes('-fullscreen', True)
                  
                          # this doesn't work
                  
                          #self.root.overrideredirect(True)
                          #self.root.geometry("800x600+100+100") # to see console behind
                          #self.root.after(5000, self.appexit) # to kill program after 5s
                  
                          self.root.bind('q', self.q_pressed)
                  
                          tk.Label(text="some text here").grid()
                          e = tk.Entry(self.root)
                          e.grid()
                          e.focus() # focus doesn't work with overrideredirect 
                  
                          tk.Button(self.root, text='Quit', command=self.appexit).grid()
                  
                          self.root.mainloop()
                  
                      def q_pressed(self, event):
                          print "q_pressed"
                          self.root.destroy()
                  
                      def appexit(self):
                          print "appexit"
                          self.root.destroy()
                  
                  App()
                  

                  这篇关于如何将 Tkinter destroy() 绑定到 Debian 中的一个键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                1. <small id='cfKAL'></small><noframes id='cfKAL'>

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

                            <tbody id='cfKAL'></tbody>
                          <tfoot id='cfKAL'></tfoot>

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