【问题标题】:Tkinter GUI doesn't work outside iPythonTkinter GUI 在 iPython 之外不起作用
【发布时间】:2013-01-05 00:07:19
【问题描述】:

我对 Python 相当陌生,但我正在尝试使用 tkinter (Python 2.7.x) 制作一个简单的 gui。我有一个功能齐全的按钮,但我只能让脚本在 iPython 中工作。当我尝试在 iPython 环境之外运行它时,我看到一些文本在命令提示符下运行但没有任何反应(即没有 gui 出现,没有任何操作发生)。

我的代码:

    import Tkinter
    from Tkinter import *
    import os

    #define frame
    root = Tk()

    frame = Frame(root)
    frame.pack()


    #define buttons
    button = Button(frame, text="Action", command= lambda: os.system("Action.py"))
    button.pack(side=LEFT)

【问题讨论】:

    标签: user-interface python-2.7 tkinter


    【解决方案1】:

    在代码末尾添加root.mainloop()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      • 2021-12-18
      • 1970-01-01
      • 2016-06-23
      相关资源
      最近更新 更多