Tkinter GUI 未在 Pydev 中打开(Liclipse)

米克尔·巴格

当我尝试基于示例 Tkinter GUI 运行我的程序时,没有任何反应。我还是 Pydev 的新手,但我发现这很不寻常。我有一个包含代码的 Main.py 文件,我尝试简单地运行该模块,但没有成功。

我只是从这个参考资料中复制/粘贴

# Main.py
import tkinter as tk;

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=root.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()

运行该模块的唯一结果是一个专用于 Main.py 的空 Liclipse 控制台。我还尝试了其他网站的其他示例,但没有成功。另外,如果重要的话,我目前在 MacOS 上。

维克多·多明戈斯

您确定在 Liclipse 中正确配置了所有内容(工作目录、python 路径...)吗?我刚刚尝试了全新安装,在将 Liclipse 配置为在 Python 3.6 中运行当前项目并选择主项目文件作为此源代码后,它按预期运行并显示一个带有按钮的窗口,它也将文本打印到控制台。

此外,以这种方式初始化按钮感觉不是很“pythonic”。我宁愿这样建议:

# Main.py
import tkinter as tk;

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        mytext = "Hello World\n(click me)"
        self.hi_there = tk.Button(self, text=mytext, command=self.say_hi)
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red", command=root.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()

代码看起来更具可读性,并且以相同的方式工作。当你开始增加你的界面时,它会有很多行,通过减少每个按钮的两行,你可以让它更短。我一直在用超过 1500 行的代码编写一个 tkinter 应用程序,那时我向自己保证我会尝试学习如何让它更有条理和更简短;)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

JToggleButton未在GUI中显示

来自分类Dev

OptionMenu()未在Tkinter中显示

来自分类Dev

未在Ubuntu 20.04中安装指纹GUI

来自分类Dev

在PyDev / LiClipse / Eclipse中设置默认工作目录

来自分类Dev

在PyDev / LiClipse / Eclipse中设置默认工作目录

来自分类Dev

打开Outlook窗口而不冻结Tkinter GUI

来自分类Dev

指令更改后,AngularJS模型更改未在GUI中显示

来自分类Dev

Swing Timer 未在 Java GUI 中启动 *已更新

来自分类Dev

Eclipse,Aptana,PyDev和LiClipse之间的关系

来自分类Dev

从Tkinter gui中更新matplotlib imshow

来自分类Dev

Tkinter功能在GUI中打印

来自分类Dev

使用tkinter在GUI中__init__

来自分类Dev

Python:在Tkinter GUI中嵌入熊猫图

来自分类Dev

消失在GUI提示中的Python Tkinter文本

来自分类Dev

对Tkinter中的GUI进行功能故障排除

来自分类Dev

从Tkinter gui中更新matplotlib imshow

来自分类Dev

用tkinter在GUI中__init__

来自分类Dev

如何在Tkinter中刷新GUI窗口

来自分类Dev

行在Tkinter GUI中无法正确显示

来自分类Dev

在 Tkinter GUI 中实现条件和循环

来自分类Dev

tkinter:由于TKinter中的单独过程,如何正确更新GUI?

来自分类Dev

图像未在Tkinter中应用到按钮上

来自分类Dev

Python Tkinter变量未在其他线程中更新

来自分类Dev

为什么打开Tkinter GUI时视觉上无法聚焦?

来自分类Dev

PyDev中的PyUnit错误

来自分类Dev

Tkinter Gui 链接按钮到 .py 文件以打开另一个 Gui

来自分类Dev

PyDev调试:不要在最后打开“ _pydev_execfile”

来自分类Dev

Tkinter GUI中的多线程,不同类中的线程

来自分类Dev

活动未在Android中打开