我看到另一个有这个问题的帖子,但解决方案对我不起作用。这段代码的两半分开工作,但不能一起工作。**(我无法让这篇文章中的缩进代码选项起作用,所以我在这里重新创建了它......所以在这一点上可能有不止一个错误......)
import wx
import numpy as np
import os
import numpy
if __name__ == "__main__":
app = wx.PySimpleApp()
wildcard = "Python source (*.py)|*.py|" \
"Compiled Python (*.pyc)|*.pyc|" \
"All files (*.*)|*.*"
dlg = wx.MessageDialog(None, "Run program?",
'Power over DeltaT',
wx.YES_NO | wx.ICON_QUESTION)
retCode = dlg.ShowModal()
if (retCode == wx.ID_YES):
dialog = wx.FileDialog(None, "File", os.getcwd(), "", wildcard, wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
x, y, z = np.loadtxt(dialog.GetPath(), dtype=float, delimiter=',',
skiprows=2,usecols=(6, 18, 19), unpack=True)
dialog.Destroy()
print x
f = (z-y) / (x+.01)
average=numpy.sum(f)/f.shape[0]
print average
dlg.Destroy()
class StaticTextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Average Watts per Delta T', size=(400, 300))
panel = wx.Panel(self, -1)
wx.StaticText(panel, -1, "The average :", (100, 100))
x=(13.21)
stra = str(x)
text = wx.StaticText(panel, -1, stra, (200, 100))
font = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)
text.SetFont(font)
app = wx.PySimpleApp()
frame = StaticTextFrame()
frame.Show()
app.MainLoop()