我正在尝试运行一个简单的 Tkinter 程序,当您单击一个按钮时它会打开一个程序。代码如下所示。我使用命令调用程序,然后调用 fortran 程序。但是,当我单击按钮时,它会打开程序,但我正在调用的程序菜单进入无限循环......违规代码似乎在 button1Click 模块中。
任何帮助是极大的赞赏。
谢谢
from Tkinter import *
import os, sys
from win32com.client import Dispatch
xlApp=Dispatch('Excel.Application')
_PSSBINPATH=r"C:\Program Files\PTI\PSSE32\PSSBIN"
os.environ['PATH']=_PSSBINPATH+';'+os.environ['PATH']
sys.path.insert(0,_PSSBINPATH)
import redirect; redirect.psse2py()
import psspy
class MyApp:
def __init__(self, parent):
self.myParent = parent ### (7) remember my parent, the root
self.myContainer1 = Frame(parent)
self.myContainer1.pack()
self.button1 = Button(self.myContainer1)
self.button1.configure(text="OK", background= "green")
self.button1.pack(side=LEFT)
self.button1.bind("<Button-1>", self.button1Click) ### (1)
self.button2 = Button(self.myContainer1)
self.button2.configure(text="Cancel", background="red")
self.button2.pack(side=RIGHT)
self.button2.bind("<Button-1>", self.button2Click) ### (2)
def button1Click(self,event): ### (3)
psspy.runiplanfile(r"C:\MNTACT\Contingency Program\work\contingency-31-4.irf")
if self.button1["background"] == "green": ### (4)
self.button1["background"] = "yellow"
else:
self.button1["background"] = "green"
def button2Click(self, event): ### (5)
self.myParent.destroy() ### (6)
root = Tk()
myapp = MyApp(root)
root.mainloop()