Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to draw simple line in wxPython?
#1
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
Quote
#2
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()
Quote
#3
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
Quote
#4
Luckily, that link includes another example that doesn't use a class :)
Quote
#5
I wasn't able to reprodure the second example with wx.ClientDC Confused
Quote
#6
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.
Quote
#7
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: https://github.com/wxWidgets/Phoenix
  • Open a command window and:
  • Unzip in a directory of your choice
  • cd to Phoenix-master/Demo/
  • run the denmo
    python demo.py
You will like it!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Problems using Wxpython Carles 1 252 Nov-28-2018, 03:09 PM
Last Post: Larz60+
  [WxPython] Using thread in the wxPython hildogjr 8 964 Aug-11-2018, 02:59 AM
Last Post: hildogjr
  Using 2 screens in wxpython Barrowman 1 561 Jun-27-2018, 07:43 PM
Last Post: Barrowman
  Trying to use code from WxPython GUI Toolkit Barrowman 3 611 Jun-26-2018, 05:43 PM
Last Post: nilamo
  A little idea to remember wxPython classes Sebastian_Adil 0 613 Mar-26-2018, 10:23 PM
Last Post: Sebastian_Adil
  moving from tkinter to wxpython Barrowman 95 9,780 Mar-25-2018, 12:39 AM
Last Post: Larz60+
  installing wxPython predirt 12 2,164 Mar-16-2018, 09:45 PM
Last Post: Barrowman
  [WxPython] wxpython and python 3.6 on linux Barrowman 3 1,662 Mar-15-2018, 06:57 PM
Last Post: Larz60+
  [Tkinter] Draw two lines and show independently in one event haha001 4 698 Feb-02-2018, 06:30 PM
Last Post: haha001
  WxPython Line Number QueenSvetlana 0 637 Dec-14-2017, 03:42 AM
Last Post: QueenSvetlana

Forum Jump:


Users browsing this thread: 1 Guest(s)