Hy
I am new in this group and I want a simple example to draw a simple line, and if it is possible by using functional style.
Thanks for your help
Hy
I am new in this group and I want a simple example to draw a simple line, and if it is possible by using functional style.
Thanks for your help
Hy
I am new in this group and I want a simple example to draw a simple line,
and if it is possible by using
functional style.
wxPython is very much an OO lib -- that's how you'll want to use it
See the wiki:
https://wiki.wxpython.org/RecipesImagesAndGraphics
maybe start here:
https://wiki.wxpython.org/VerySimpleDrawing
-CHB
On Tue, Mar 20, 2018 at 11:16 PM, Gourinda Adil <gourindaadil@gmail.com> wrote:
Thanks for your help
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
I know those two links, but I found them difficult
Depending on what you want to accomplish, you may also consider a Matplotlib canvas, either standalone or embedded into a wxPython application.
https://matplotlib.org/users/pyplot_tutorial.html
https://github.com/matplotlib/matplotlib/tree/master/examples/user_interfaces
Regards,
Dietmar
On 3/21/2018 1:53 PM, Gourinda Adil wrote:
I know those two links, but I found them difficult
Gourinda Adil wrote:
I am new in this group and I want a simple example to draw a simple line, and if it is possible by using functional style.
Your request is an odd one, because "drawing a line" is not the tricky
part of a GUI application. There's much more to learn about windows,
events, controls, sizers, DCs, and so on. Here's a complete app that
creates a window and draws a line from upper left to lower right.
----- -----
import wx
class MainPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self,parent)
self.Bind(wx.EVT_PAINT, self.onPaint)
def onPaint\(self, evt\):
dc = wx\.PaintDC\(self\)
r = self\.GetClientRect\(\)
dc\.DrawLine\( 0, 0, r\.right, r\.bottom \)
class MainFrame(wx.Frame):
def __init__(self,):
wx.Frame.__init__(self, None, title="test")
self.panel = MainPanel(self)
self.Show()
app = wx.App(0)
frame = MainFrame()
app.MainLoop()
----- -----
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
I am not a programmer but I have I need to learn programming especially the GUI, before I was working with Tkinter, it is so easy to understand the basics of GUI but its developers are not interested in, so I decided to move to wxPython, working with its basic widgets is good but when I tried to draw with it => SHOCK.
This my litle example you can laught on it but Please I need help:
==========
import wx
app = wx.App()
frame = wx.Frame(parent=None ,title=“hallo”)
draw = wx.ClientDC(frame)
draw.DrawCircle(150 ,150 ,50)
frame.Show(True)
What I missed?
Thanks for your help
Gourinda Adil wrote:
I am not a programmer but I have I need to learn programming
especially the GUI, before I was working with Tkinter, it is so easy
to understand the basics of GUI but its developers are not interested
in, so I decided to move to wxPython, working with its basic widgets
is good but when I tried to draw with it => SHOCK.This my litle example you can laught on it but Please I need help:
Partly what you're missing here is the way windowing systems work. You
have to stop thinking of things in terms of a simple sequence of
functions from front to back. Instead, everything is based on the
passing and handling of messages. You aren't really in control here;
the windowing system is. When you create a window, that window is not
created immediately. Instead, it creates a couple of data structures,
and then issues messages that trigger the actual window to be created,
registered, and drawn. The messages are all received and dispatched by
your main loop, so none of those messages can be handled until you call
app.MainLoop. That's the basic problem with your code. When you call
the wx.Frame initializer, the window does not actually exist on the
screen yet, so there's no place for your circle to go.
In your case, you even called the DrawCircle before you called
frame.Show, so even if the window hadn't been created, it wouldn't be
shown on the screen. Windows only exist on the screen -- there is no
backing bitmap. So, unless your window is visible, any drawing you do
is thrown away.
Did you look at my example? That shows the basic minimum app for what
you ask. I create a frame, I create a panel on the frame, and I call
the main loop. Once the window is created, the windowing system will
sent a "paint" message to all of the windows telling each to paint
itself. I register a handler for the EVT_PAINT message, and inside that
handler is where I do my drawing.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Hi,
You really need to handle painting with some onPaint method of some
custom class, just as was shown in the sample code by Tim Roberts.
Your code could "kind of" work, if you do the drawing after the
window/frame was shown, e.g.:
import wx
app = wx.App()
frame = wx.Frame(parent=None, title="hallo")
frame.Show(True)
draw = wx.ClientDC(frame)
draw.DrawCircle(150, 150, 50)
app.MainLoop()
This way a circle is drawn as specified, but it doesn't probably work
as intended - subsequent (re)drawing is happening under the hood -
e.g. after resizing or minimising the frame, after some other window
is maximised over this frame etc. - in these cases the initially drawn
circle is lost.
It is necessary to handle redrawing of the needed elements
automatically on each paint-event, just like it is shown in the sample
code.
hth,
vbr
2018-03-21 22:12 GMT+01:00 Gourinda Adil <adilsebastian81@gmail.com>:
I am not a programmer but I have I need to learn programming especially the
GUI, before I was working with Tkinter, it is so easy to understand the
basics of GUI but its developers are not interested in, so I decided to move
to wxPython, working with its basic widgets is good but when I tried to draw
with it => SHOCK.This my litle example you can laught on it but Please I need help:
import wx
app = wx.App()
frame = wx.Frame(parent=None ,title="hallo")
draw = wx.ClientDC(frame)
draw.DrawCircle(150 ,150 ,50)frame.Show(True)
app.MainLoop()
What I missed?
Thanks for your help
--
Sorry “vbr”, I tried your example even if no window in my desktop is opened (except the IDLE), I get an empty frame
Thanks all of you for your HELP
well, tk has a canvas widget, which does relieve you of having to deal with
much of the custom drawing stuff.
you might want to use floatcanvas:
#!/usr/bin/env pythonw
import wx
from wx.lib.floatcanvas import NavCanvas
class DrawFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.CreateStatusBar()
# Add the Canvas
Canvas = NavCanvas.NavCanvas(self,
BackgroundColor="DARK SLATE BLUE",
).Canvas
self.Canvas = Canvas
Canvas.AddLine(((10, 10), (50, 50)),
LineColor="Red",
LineWidth=4,
)
self.Show()
Canvas.ZoomToBB()
app = wx.App(False)
F = DrawFrame(None,
title="FloatCanvas Demo App",
size=(700, 700)
)
app.MainLoop()
On Wed, Mar 21, 2018 at 9:12 PM, Gourinda Adil <adilsebastian81@gmail.com> wrote:
I am not a programmer but I have I need to learn programming especially
the GUI, before I was working with Tkinter, it is so easy to understand the
basics of GUI but its developers are not interested in, so I decided to
move to wxPython, working with its basic widgets is good but when I tried
to draw with it => SHOCK.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
How can I reproduce the second example using wx.ClientDC:
Gourinda Adil wrote:
How can I reproduce the second example using wx.ClientDC:
You don't, and you don't need to. Anything you can do with a ClientDC
can be done with a PaintDC.
The basic object that lets you do drawing is a DC. All of the classes
that derive from DC can do the exact same drawing. However, the way you
GET a DC varies depending on where you are. If you are inside an
EVT_PAINT handler, then you must use wx.PaintDC. The system only sends
you EVT_PAINT if it thinks that parts of your window need to be
recreated. There are special APIs that an application uses to tell the
system "OK, my window is up to date", and the wx.PaintDC class takes
care of that. If you don't use wx.PaintDC, then when your EVT_PAINT
handler returns, the system will think "uh-oh, they didn't update their
window", and it will call EVT_PAINT again. And again. And again.
If you are inside any other kind event handler, then that update region
thing does not apply, and you use wx.ClientDC to get your DC.
So, if you want to explore drawing with a DC using that example, then
just use the PaintDC.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
You don't, and you don't need to. Anything you can do with a ClientDC
can be done with a PaintDC.
And by the way, you almost never want to use a ClientDC these days anyway.
Do all your drawing in a PaintDC in a function called by EVT_PAINT.
If you want to update the drawing, call .Update() and .Refresh().
That will trigger a paint event in a way that is better synchronized
with the system.
And you can do all of your drawing in one way, in one place.
CHB
The basic object that lets you do drawing is a DC. All of the classes
that derive from DC can do the exact same drawing. However, the way you
GET a DC varies depending on where you are. If you are inside an
EVT_PAINT handler, then you must use wx.PaintDC. The system only sends
you EVT_PAINT if it thinks that parts of your window need to be
recreated. There are special APIs that an application uses to tell the
system "OK, my window is up to date", and the wx.PaintDC class takes
care of that. If you don't use wx.PaintDC, then when your EVT_PAINT
handler returns, the system will think "uh-oh, they didn't update their
window", and it will call EVT_PAINT again. And again. And again.If you are inside any other kind event handler, then that update region
thing does not apply, and you use wx.ClientDC to get your DC.So, if you want to explore drawing with a DC using that example, then
just use the PaintDC.--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.