我想开发一个GUI应用程序,允许我绘制烛台条,然后在绘图上手动绘制线条。
我在Linux上工作,所以更喜欢跨平台的解决方案,或者至少在Linux上运行。我倾向于使用Python很多,并且过去使用过C#(在Linux上使用mono)。我做了一些研究,似乎建议wxPython或PyQwt(两者都与matplotlib一起使用)是可行的方法。我承认我偏向于Python,因为我现有的很多脚本都是用Python编写的。但是,C#有一个很好的GUI库,如果它是这个实例中更好的工具,那么我愿意使用它而不是基于Python的解决方案。
申请的要求如下:
由于wxPython,PyQwt和C#(一般来说)对我来说都是新手,我想知道哪个:
显示一个让我入门的准系统骨架的片段(使用wxPython,pyQt,pyQwt或C#)将非常有用。
答案 0 :(得分:0)
wxPython中的简单快速示例:
import wx
import math
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
class Graph(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
self.figure = Figure()
self.canvas = FigureCanvas(self, -1, self.figure)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
size = self.GetSize()
self.canvas.SetSize(size)
def Draw(self):
self.figure.clear()
self.subplot = self.figure.add_subplot(111)
x = [a*(math.pi/50) for a in range(100)]
y = [self.f(a) for a in x]
self.subplot.plot(x, y)
self.canvas.draw()
def DrawCosine(self, e):
self.f = math.cos
self.Draw()
def DrawSine(self, e):
self.f = math.sin
self.Draw()
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.panel = wx.Panel(self)
self.button1 = wx.Button(self.panel, label="Sine")
self.button2 = wx.Button(self.panel, label="Cosine")
self.graph = Graph(self.panel)
self.graph.DrawSine(None)
self.button1.Bind(wx.EVT_BUTTON, self.graph.DrawSine)
self.button2.Bind(wx.EVT_BUTTON, self.graph.DrawCosine)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer2 = wx.BoxSizer()
self.sizer.Add(self.graph, 1, wx.ALL | wx.EXPAND)
self.sizer2.Add(self.button1, 1, wx.ALL | wx.EXPAND)
self.sizer2.Add(self.button2, 1, wx.ALL | wx.EXPAND)
self.sizer.Add(self.sizer2, 0, wx.ALL | wx.EXPAND)
self.panel.SetSizerAndFit(self.sizer)
self.Show()
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
但根据您的要求,使用(或稍微重新设计)pyplot
就足够了:
import wx
import math
from matplotlib import pyplot
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.panel = wx.Panel(self)
self.button1 = wx.Button(self.panel, label="Sine")
self.button2 = wx.Button(self.panel, label="Cosine")
self.button1.Bind(wx.EVT_BUTTON, self.DrawSine)
self.button2.Bind(wx.EVT_BUTTON, self.DrawCosine)
self.sizer = wx.BoxSizer()
self.sizer.Add(self.button1)
self.sizer.Add(self.button2)
self.panel.SetSizerAndFit(self.sizer)
self.Show()
def Draw(self):
x = [a*(math.pi/50) for a in range(100)]
y = [self.f(a) for a in x]
pyplot.plot(x, y)
pyplot.grid(True, which='both', axis="both")
pyplot.show()
def DrawCosine(self, e):
self.f = math.cos
self.Draw()
def DrawSine(self, e):
self.f = math.sin
self.Draw()
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
答案 1 :(得分:0)
wxpython更适合您的目的。存在一个非常好的教程,涵盖了大多数基础知识here。