点击“赢取”不会触发事件。
我正在为python中的简单数据可视化创建一个简单的GUI
似乎有些东西阻挡了按钮和选择,实际上是主面板中的任何内容。
它正在工作,但后来我从matplotlib放置了图表 我怀疑它与放置/盒装大师有关,但不能解决我的生活问题。
非常感谢任何帮助。
import sys
from random import *
import signal
import sqlite3
from datetime import date, datetime
import wx
import wx.lib.mixins.inspection as WIT
import matplotlib
from numpy import arange, sin, pi
matplotlib.use('WX')
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
class myGui(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title)
self.parent = parent
self.initialise()
pnl = wx.Panel(self)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
rightMenuBtns = wx.BoxSizer(orient=wx.VERTICAL)
self.sizer.Add(rightMenuBtns, proportion = 1, flag=wx.LEFT | wx.ALL, border = 5)
self.sizer.Add(self.canvas, 1, wx.RIGHT | wx.TOP | wx.EXPAND)
fileMenu = wx.Menu()
loadFile = fileMenu.Append(wx.ID_OPEN)
exitItem = fileMenu.Append(wx.ID_EXIT)
helpMenu = wx.Menu()
aboutItem = helpMenu.Append(wx.ID_ABOUT)
self.problems = wx.Choice(pnl,choices = allProblems())
rightMenuBtns.Add(self.problems, proportion = 1, flag=wx.CENTER | wx.ALL, border = 5)
self.solutions = wx.Choice(pnl,choices = allSolutionsText(allProblems()[self.problems.GetSelection()]))
rightMenuBtns.Add(self.solutions, proportion = 1, flag=wx.CENTER | wx.ALL, border = 5)
solve = wx.Button(pnl, label="SOLVE")
rightMenuBtns.Add(solve, proportion = 1, flag=wx.CENTER | wx.ALL, border = 5)
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
menuBar.Append(helpMenu, "&Help")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnExit, exitItem)
self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)
self.Bind(wx.EVT_MENU, self.loadFile, loadFile)
self.Bind(wx.EVT_BUTTON, self.Solve, solve)
self.solutions.Bind(wx.EVT_CHOICE, self.Solutions)
self.problems.Bind(wx.EVT_CHOICE, self.Problems)
self.dlg = wx.TextEntryDialog(pnl, 'Enter the amount of seconds you want to run solver for:','Time')
self.SetSizer(self.sizer)
self.Fit()
def initialise(self):
self.Show(True)
def OnExit(self, event):
self.Close(True)
def OnAbout(self, event):
wx.MessageBox("Hello",
"Made By Thomas Csere", wx.OK | wx.ICON_INFORMATION)
def loadFile(self, event):
openFileDialog = wx.FileDialog(self, "Open", "", "",
"Traveling Salesman Problem (*.tsp)|*.tsp",
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
openFileDialog.ShowModal()
addProblem(openFileDialog.GetPath())
wx.MessageBox("Problem Added")
openFileDialog.Destroy()
def Problems(self,event):
print("woo")
self.solutions.Clear()
self.solutions.AppendItems(allSolutionsText(allProblems()[self.problems.GetSelection()]))
def Solutions(self,event):
print("yay")
def Solve(self,event):
self.dlg.ShowModal()
if(self.problems.GetSelection()>=0):
solveFull(allSolutionsText(allProblems()[self.problems.GetSelection()], self.dlg.GetValue()))
app = wx.App()
frame = myGui(None,-1,"My Application")
app.MainLoop()
答案 0 :(得分:0)
您永远不会将面板添加到sizer中,因此它可能与FigureCanvas重叠。
此外,通常更好的做法是不要长时间创建和保持对话。只需在您需要显示它们时创建它们,然后在获取其值后Destroy
。