<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
 
<meta name="Generator" content="Kate, the KDE Advanced Text Editor">
<pre><span style="color: rgb(128, 128, 128);"><i>#!/usr/bin/python</i></span>

<span style="color: rgb(128, 128, 128);"><i># In this program I wanted to write the event &lt;B1-Motion&gt; on my own, combining &lt;Button-1&gt;, &lt;Motion&gt; and &lt;ButtonRelease-1&gt;,
# but unfortunetly it doesn't work. No syntax errors.

</i></span> <span style="color: rgb(255, 0, 255);">from</span> Tkinter <span
 style="color: rgb(255, 0, 255);">import</span> <span
 style="color: rgb(255, 0, 255);">*</span>


<b>def</b> handler<span style="color: rgb(255, 0, 255);">(</span>event<span
 style="color: rgb(255, 0, 255);">):</span>
        <b>if</b> buttonpressed <span
 style="color: rgb(255, 0, 255);">==</span> <span
 style="color: rgb(0, 0, 255);">1</span> <span
 style="color: rgb(255, 0, 255);">:</span>
                <span
 style="color: rgb(128, 128, 128);"><i>#if the mousebutton is pressed and moved, circles should appear, but they do not</i></span>
                can.create_oval<span
 style="color: rgb(255, 0, 255);">(</span>event.x<span
 style="color: rgb(255, 0, 255);">-</span>r, event.y<span
 style="color: rgb(255, 0, 255);">-</span>r, event.x<span
 style="color: rgb(255, 0, 255);">+</span>r, event.y<span
 style="color: rgb(255, 0, 255);">+</span>r, fill<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(221, 0, 0);">"orange"</span><span
 style="color: rgb(255, 0, 255);">)</span>
        lab.config<span
 style="color: rgb(255, 0, 255);">(</span>text<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(221, 0, 0);">'buttonpressed='</span> <span
 style="color: rgb(255, 0, 255);">+</span> <span
 style="color: rgb(128, 0, 0);">str</span><span
 style="color: rgb(255, 0, 255);">(</span>buttonpressed<span
 style="color: rgb(255, 0, 255);">)</span> <span
 style="color: rgb(255, 0, 255);">)</span>

<b>def</b> press<span style="color: rgb(255, 0, 255);">(</span>event<span
 style="color: rgb(255, 0, 255);">):</span>
        buttonpressed<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(0, 0, 255);">1</span>
        lab2.config<span
 style="color: rgb(255, 0, 255);">(</span>text<span
 style="color: rgb(255, 0, 255);">=</span>buttonpressed<span
 style="color: rgb(255, 0, 255);">)</span>
        
<b>def</b> release<span style="color: rgb(255, 0, 255);">(</span>event<span
 style="color: rgb(255, 0, 255);">):</span>
        buttonpressed<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(0, 0, 255);">0</span>
        lab2.config<span
 style="color: rgb(255, 0, 255);">(</span>text<span
 style="color: rgb(255, 0, 255);">=</span>buttonpressed<span
 style="color: rgb(255, 0, 255);">)</span>        


r<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(0, 0, 255);">5</span>
<span style="color: rgb(128, 128, 128);"><i>#global buttonpressed</i></span>
buttonpressed<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(0, 0, 255);">0</span>

root <span
 style="color: rgb(255, 0, 255);">=</span> Tk<span
 style="color: rgb(255, 0, 255);">()</span>
root.geometry<span
 style="color: rgb(255, 0, 255);">(</span><span
 style="color: rgb(221, 0, 0);">'600x500+200+200'</span><span
 style="color: rgb(255, 0, 255);">)</span>

<span style="color: rgb(128, 128, 128);"><i># both labels are used to check the status of the variable buttonpressed</i></span>
lab <span
 style="color: rgb(255, 0, 255);">=</span> Label<span
 style="color: rgb(255, 0, 255);">(</span>root, text<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(221, 0, 0);">'cucc'</span><span
 style="color: rgb(255, 0, 255);">)</span>
lab2 <span
 style="color: rgb(255, 0, 255);">=</span> Label<span
 style="color: rgb(255, 0, 255);">(</span>root, text<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(221, 0, 0);">'cucc2'</span><span
 style="color: rgb(255, 0, 255);">)</span>

can <span
 style="color: rgb(255, 0, 255);">=</span> Canvas<span
 style="color: rgb(255, 0, 255);">(</span>root, width<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(221, 0, 0);">'500'</span>, height<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(221, 0, 0);">'400'</span>, bg<span
 style="color: rgb(255, 0, 255);">=</span><span
 style="color: rgb(221, 0, 0);">'white'</span><span
 style="color: rgb(255, 0, 255);">)</span>
can.bind<span
 style="color: rgb(255, 0, 255);">(</span><span
 style="color: rgb(221, 0, 0);">"&lt;Motion&gt;"</span>,handler<span
 style="color: rgb(255, 0, 255);">)</span>
can.bind<span
 style="color: rgb(255, 0, 255);">(</span><span
 style="color: rgb(221, 0, 0);">"&lt;Button-1&gt;"</span>,press<span
 style="color: rgb(255, 0, 255);">)</span>
can.bind<span
 style="color: rgb(255, 0, 255);">(</span><span
 style="color: rgb(221, 0, 0);">"&lt;ButtonRelease-1&gt;"</span>,release<span
 style="color: rgb(255, 0, 255);">)</span>

lab.pack<span
 style="color: rgb(255, 0, 255);">()</span>
lab2.pack<span
 style="color: rgb(255, 0, 255);">()</span>
can.pack<span
 style="color: rgb(255, 0, 255);">()</span>

root.mainloop<span
 style="color: rgb(255, 0, 255);">()</span>
</pre>
</body>
</html>