【发布时间】:2018-09-11 04:16:37
【问题描述】:
我目前对 Python 和一般编码是全新的,只是想尝试制作 4 个按钮的布局,单击时打开不同的程序。截至目前,我的代码如下所示。
from tkinter import *
import os
import subprocess
root=Tk()
root.geometry('750x650')
root.title('Test')
topFrame = Frame(root)
topFrame.pack(side=TOP, fill='both')
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM, fill='both')
button1 = Button(topFrame, text="Button1", fg="black")
button2 = Button(topFrame, text="Button2", fg="black")
button3 = Button(bottomFrame, text="Button3", fg="black")
button4 = Button(bottomFrame, text="Button4", fg="black")
button1.config(height=21, width=52)
button2.config(height=21, width=52)
button3.config(height=21, width=52)
button4.config(height=21, width=52)
button1.pack(side='left', fill='both')
button2.pack(side='right', fill='both')
button3.pack(side='left', fill='both')
button4.pack(side='right', fill='both')
app = Application(root)
root.mainloop()
有什么建议吗?
【问题讨论】:
-
您到底在寻找什么?您还没有添加按钮按下的回调函数,您希望触发哪些程序?
-
我尝试使用 App 类:但我得到的只是错误
-
我只是试图让按钮触发 CCleaner 和 Adwcleaner 等程序的启动。我添加了一个 command=self.openfile 并无法让它工作
-
我没有看到您的代码中定义了任何名为 Application 的类,如果您还没有定义任何类,请删除行 app = Application(root)
-
是的,我在发布后删除了它。因为我看到它不应该在那里,因为它没有被定义。
标签: python tkinter callback subprocess