Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how to draw simple line in wxPython?
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
What do you have so far?

Have you tried this?
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.SetPen(wx.Pen(wx.BLACK, 4))
        dc.DrawLine(0, 0, 50, 50)

app = wx.App(False)
frame = DrawPanel()
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
Luckily, that link includes another example that doesn't use a class :)
I wasn't able to reprodure the second example with wx.ClientDC Confused
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.
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:
  • Download the source here:
  • Open a command window and:
  • Unzip in a directory of your choice
  • cd to Phoenix-master/Demo/
  • run the denmo
You will like it!

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [WxPython] Adding a Window to a Button wxPython ShashankDS 4 331 Apr-23-2019, 06:53 PM
Last Post: Yoriz
  WxPython in web with a cgi server jttolleson 11 734 Mar-08-2019, 05:54 PM
Last Post: Weave
  Problems using Wxpython Carles 1 537 Nov-28-2018, 03:09 PM
Last Post: Larz60+
  [WxPython] Using thread in the wxPython hildogjr 8 1,613 Aug-11-2018, 02:59 AM
Last Post: hildogjr
  Using 2 screens in wxpython Barrowman 1 768 Jun-27-2018, 07:43 PM
Last Post: Barrowman
  Trying to use code from WxPython GUI Toolkit Barrowman 3 963 Jun-26-2018, 05:43 PM
Last Post: nilamo
  A little idea to remember wxPython classes Sebastian_Adil 0 785 Mar-26-2018, 10:23 PM
Last Post: Sebastian_Adil
  installing wxPython predirt 12 3,466 Mar-16-2018, 09:45 PM
Last Post: Barrowman
  [WxPython] wxpython and python 3.6 on linux Barrowman 3 2,578 Mar-15-2018, 06:57 PM
Last Post: Larz60+
  [Tkinter] Draw two lines and show independently in one event haha001 4 1,030 Feb-02-2018, 06:30 PM
Last Post: haha001

Forum Jump:

Users browsing this thread: 1 Guest(s)