윈도우에 선 긋는 파이썬 예제
#!/usr/bin/env python
# -*- coding: CP949 -*-
#
# generated by wxGlade 0.7.2 on Tue Apr 05 01:49:01 2016
#
import wx
# begin wxGlade: dependencies
import gettext
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MainPlotFrame(wx.Frame):
canvas = 1
x00=0
y00=0
def __init__(self, *args, **kwds):
# begin wxGlade: MainPlotFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.canvas = wx.StaticBitmap(self, -1, wx.Bitmap("sample.png", wx.BITMAP_TYPE_ANY))
self.canvas.Bind(wx.EVT_LEFT_DOWN, self.positionnow)
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MainPlotFrame.__set_properties
self.SetTitle(("frame_1"))
self.SetSize((1024, 768))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MainPlotFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
def positionnow(self, event):
self.x00=wx.MouseEvent.GetX(event)
self.y00=wx.MouseEvent.GetY(event)
print((wx.MouseEvent.GetX(event),wx.MouseEvent.GetY(event)))
self.drawTick(self.x00,self.y00,self.x00+100,self.y00-30)
def drawTick(self, x0, y0, x1, y1):
self.mydc = wx.MemoryDC()
frame_main.canvas2 = wx.Bitmap("sample.png", wx.BITMAP_TYPE_ANY)
self.mydc.SelectObject(self.canvas2)
self.mydc.SetPen(wx.Pen(self.colorDecision(),1))
self.mydc.DrawLine(x0, y0, x1, y1)
self.mydc.SelectObject(wx.NullBitmap)
self.canvas.SetBitmap(self.canvas2)
self.mydc = None
self.canvas = wx.StaticBitmap(self, -1, self.canvas2)
return 0
def colorDecision(self):
return wx.Colour(255, 0,0)
# end of class MainPlotFrame
# end of class MainPlotFrame
if __name__ == "__main__":
app = wx.App(0)
#~ wx.InitAllImageHandlers()
frame_main = MainPlotFrame(None, -1, "")
frame_main.Show()
app.MainLoop()
--
언젠가는 써먹겠지...