how to draw simple line in wxPython? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: how to draw simple line in wxPython? (/thread-9107.html) |
how to draw simple line in wxPython? - Sebastian_Adil - Mar-21-2018 Hy I am new in wxPython and I want a simple example to draw a simple line, and if it is possible by using functional style. Thanks for your help RE: how to draw simple line in wxPython? - nilamo - Mar-21-2018 What do you have so far? Have you tried this? https://wiki.wxpython.org/VerySimpleDrawing Quote:import wx class DrawPanel(wx.Frame): """Draw a line to a panel.""" def __init__(self): wx.Frame.__init__(self, title="Draw on Panel") self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, event=None): dc = wx.PaintDC(self) dc.Clear() dc.SetPen(wx.Pen(wx.BLACK, 4)) dc.DrawLine(0, 0, 50, 50) app = wx.App(False) frame = DrawPanel() frame.Show() app.MainLoop() RE: how to draw simple line in wxPython? - Sebastian_Adil - Mar-21-2018 Before I was working with Tkinter and most of my examples was in functional style so I am not so good with classes and I don't want to build a class for only testing a widget RE: how to draw simple line in wxPython? - nilamo - Mar-21-2018 Luckily, that link includes another example that doesn't use a class :) RE: how to draw simple line in wxPython? - Sebastian_Adil - Mar-22-2018 I wasn't able to reprodure the second example with wx.ClientDC RE: how to draw simple line in wxPython? - nilamo - Mar-22-2018 I just tried it (had to install wx first, since I didn't have it), and it worked for me as written. So if it isn't working, please share your code, and the error message. RE: how to draw simple line in wxPython? - Larz60+ - Mar-22-2018 You really should get yourself comfortable with classes. GUI programming involves so many layers that It's very difficult to do without. So many methods rely of inheriting from other methods and classes that it is very difficult to do all but the simplest of code without using classes. One way to improve your understanding of this is to load the python demo program, which is very complete and backed by source code, available with a single click of a notebook tab allowing you to flip between demo and source code while trying to understand a concept. To get this demo:
|