Python Forum
how to draw simple line in wxPython?
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
Reply
#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()
Reply
#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
Reply
#4
Luckily, that link includes another example that doesn't use a class :)
Reply
#5
I wasn't able to reprodure the second example with wx.ClientDC Confused
Reply
#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.
Reply
#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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WxPython Line Number QueenSvetlana 0 2,383 Dec-14-2017, 03:42 AM
Last Post: QueenSvetlana

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020