Pysimplegui 简明教程

PySimpleGUI - Debugger

除了大多数 IDE(例如 PyCharm 或 VS Code)内置的调试器以外,PySimpleGUI 还提供自有的调试器。在代码运行时,此调试器可让你“查看”代码并与之交互。

In addition to the built-in debugger that most IDEs such as PyCharm or VS Code have, PySimpleGUI offers its own debugger. This debugger provides you the ability to "see" and interact with your code, while it is running.

若要有效使用调试器服务,应异步重新着色窗口,即应向 read() 函数提供超时。

To use the debugger service effectively, the window should be red asynchronously, i.e., you should provide a timeout to the read() function.

通过按如下所示在程序内的任意位置调用 show_debugger_window() 函数来调用调试器窗口 -

The debugger window is invoked by calling show_debugger_window() function anywhere inside the program as shown below −

import PySimpleGUI as sg
sg.show_debugger_window(location=(10,10))
window = sg.Window('Debugger Demo',
   [[sg.Text('Debugger'),
   sg.Input('Input here'),
   sg.Button('Push Me')]]
)
while True:
   event, values = window.read(timeout=500)
   if event == sg.TIMEOUT_KEY:
      continue
   if event == sg.WIN_CLOSED:
      break
   print(event, values)
window.close()

此外,PySimpleGUI 调试器窗口会出现在指定的屏幕位置。

The PySimpleGUI debugger window appears at the specified screen location.

gui debugger

此窗口将显示两个选项卡:变量和 REPL。单击变量选项卡。将显示要自动监视的变量列表,在此处选中那些你希望在程序执行期间查看的变量。

The window shows two tabs Variables and REPL. Click on the Variables tab. A list of variables to auto-watch is shown Check the ones that you want to watch during the execution of the program.

all locals

有关 REPL 的帮助选项卡提供了一个 Python 交互式控制台,可在程序环境中执行,以便你可以检查代码中所需变量的值。

The second tab about REPL gives a Python interactive console to be executed around your program’s environment so that you can inspect the values of desired variables in the code.

debugging