2017-09-23 93 views
1

點擊不會觸發事件。wxpython按鈕被阻止/未點擊

我正在爲簡單的數據可視化一個簡單的GUI在python

好像有物體擋住了按鈕和選擇,在主面板真的什麼。

它正在工作,但隨後我從matplotlib中放置了圖表 我懷疑這是與展示位置/ boxsizers有關,但無法爲我的生活弄清楚。

任何幫助,非常感謝。

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