Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:16:12+00:00 2026-06-06T22:16:12+00:00

I am trying for a long time to figure how to proceed arguments in

  • 0

I am trying for a long time to figure how to proceed arguments in Python, also name scoping rules gives me some hard times.
I’m working with SVG+Javascript which is soooo simple to deal with and I wrote some essential code in JS just to explain me on example, because reading about Python didn’t solve my stupidity. THIS is link where you may see below code in action. So simple.

<svg id="svgRoot" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect id="background" x="1%" y="2%" width="98%" height="97%" fill="khaki" onmousedown="takePos(evt)" />
<script type="text/ecmascript">
<![CDATA[
var x1, x2;
var Root=document.documentElement;

function takePos(evt){
  x1=evt.clientX;
  y1=evt.clientY;
  var w=0;
  var h=0;
  Root.setAttributeNS(null, "onmousemove", "mouseMove(evt)");
  Root.setAttributeNS(null, "onmouseup", "endPos()");
  buildRect(w, h);
}
function mouseMove(evt){
  var w=evt.clientX-x1;
  var h=evt.clientY-y1;
  var r=document.getElementById("svgRoot").lastChild;
  if ((w>0)&&(h>0)) {
    r.setAttributeNS(null, "width", w);
    r.setAttributeNS(null, "height", h);
  }
}
function endPos(){
  Root.setAttributeNS(null, "onmousemove", null);
  Root.setAttributeNS(null, "onmouseup", null);
}
function buildRect(w, h){
  var cont=document.getElementById("svgRoot");
  var r=document.createElementNS("http://www.w3.org/2000/svg", "rect");
  r.setAttributeNS(null, "id", "svgR");
  r.setAttributeNS(null, "x", x1);
  r.setAttributeNS(null, "y", y1);
  r.setAttributeNS(null, "width", w);
  r.setAttributeNS(null, "height", h);
  r.setAttributeNS(null, "rx", "10");
  r.setAttributeNS(null, "fill", "darkblue");
  r.setAttributeNS(null, "fill-opacity", "0.5");
  cont.appendChild(r);
}
]]>
</script>

</svg>

The simplest mouse drawing rectangle. And now bellow is my Titanic try to write something like that in wx.Python.

#   HOW TO DRAW RECTANGLE AS IN MY SVG-EXAMPLE ?

import wx

class MyPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)
        self.SetBackgroundColour('white')
        self.Bind(wx.EVT_LEFT_DOWN, self.onDown)
        self.Bind(wx.EVT_MOTION, self.onMove)
        self.Bind(wx.EVT_LEFT_UP, self.onUp)

    def onDown(self, evt):
        pt1 = evt.GetPosition() # firstPosition tuple
        w = pt1.x   # starting with zero width and height
        h = pt1.y
        self.drawRect(pt1, w, h)    #??? args

    def onMove(self, evt):
        pt2 = evt.GetPosition() 
        w = pt2.x - pt1.x
        h = pt2.y - pt1.y
        # should to append new width and height while moving

    def onUp(self):
        #  had to finish drawing

    def drawRect(self, pt1, w, h):
        pdc = wx.PaintDC(self)
        try:
            # needed to give realistic transparency 
            dc = wx.GCDC(pdc)
        except:
            # wx.PaintDC alone will not give transparency
            dc = pdc
        r, g, b = (30, 140, 220)
        pencolour = wx.Colour(r, g, b, 180)
        brushcolour = wx.Colour(r, g, b, 120)
        dc.SetPen(wx.Pen(pencolour))
        dc.SetBrush(wx.Brush(brushcolour))
        rect = wx.Rect(pt1, w, h)
        dc.DrawRoundedRectangleRect(rect, 8)




app = wx.App(0)
caption = "wx.GCDC() is here to achieve transparency"
frame = wx.Frame(None, wx.ID_ANY, caption, size=(400, 310))
MyPanel(frame)
frame.Show(True)
app.MainLoop()

Please refer to Javascript code to explain me how to do the job in wx.Python. I already tryed to read examples on Internet and from books. Other things in Python seems so simple and logical with no hassling at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:16:14+00:00Added an answer on June 6, 2026 at 10:16 pm

    Since you are using a class (MyPanel), you should store your rectangles/data in class members (using self).

    E.g. (untestet, but you’ll get the idea):

    def __init__(self, ...)
        ...
        self.pt1 = None
        self.pt2 = None
        self.rects = []
    
    def onDown(self, evt):
        self.pt1 = evt.GetPosition() # new start position
    
    def onMove(self, evt):
        self.pt2 = evt.GetPosition() # end position
    
    def onUp(self, evt):
        # if mouse is released, store the points in the list
        self.rects.append((self.pt1, self.pt2))
        self.pt1 = self.pt2 = None
    
    def onDraw(self, evt):
        dc = wx.PaintDC(self)
    
        # if we are currently creating a new rect, draw it
        if self.pt1 and self.pt2:
            self.drawRect(dc, self.pt1, self.pt2)
    
        # draw all finished rects
        for p1, p2 in self.rects:
            self.drawRect(dc, p1, p2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just spent a long time trying to figure out why my Javascript for()
I have now used way too long time, trying to figure out a problem,
I have been trying to figure out whats wrong for quite long time yet
I'm trying to figure out where our project went wrong. A long time ago,
For a long time i have been trying to figure out what is the
Ok, I have been trying to figure this out for a long time now
long time reader, first time writer here. I'm trying to figure out all possible
Long-time reader, first-time poster here. I'm trying to figure out how to sort a
Table #1: qa_returns_items Table #2: qa_returns_residues I have a long time trying to get
I'm new to Android programming. I spent a long time trying to look for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.