473,785 Members | 2,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

drawline

I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:
First, Clicknum increases when every time I click the button. Is it
possible to reset Clicknum to 0?
Second, how to do something like: I click the left button the first
time, the green line appear then disappear, the purple line
appear(just as the code has done but become a loop; if a second-time
click is implied, the loop stops.
from Tkinter import *

ClickNum = 0

def drawline(event) :
global ClickNum
if ClickNum == 0:
canvas.create_l ine(100, 0, 100, 200, arrow=FIRST,fil l="green",tag=" a")
elif ClickNum == 1:
canvas.delete(" a")
canvas.create_l ine(100, 50, 60, 300, arrow=FIRST,fil l="purple")
ClickNum += 1

tk = Tk()
canvas = Canvas(tk, bg="white", bd=0, highlightthickn ess=0)
canvas.pack(fil l=BOTH, expand=YES)
canvas.create_l ine(100, 200, 350, 200, arrow=LAST,fill ='red')
canvas.bind("<1 >", drawline)
tk.mainloop()
Nov 22 '05 #1
3 3169
Hi Ben,
if I understood your questions properly, this code gives some answers (on
XP):

from Tkinter import *

lines = [
[ (100, 200, 350, 200), LAST, "red", '' ],
[ (100, 0, 100, 200), FIRST, "green", 'a' ],
[ (100, 200, 300, 100), LAST, "purple", 'b' ],
]

ClickMax = len(lines)
ClickNum = 0
lasttag = ''

def drawline(event) :
global ClickNum,lastta g
canvas.delete(l asttag)
line = lines[ClickNum]
canvas.create_l ine(line[0], arrow=line[1], fill=line[2],tag=line[3])
lasttag = line[3]
ClickNum = (ClickNum+1) % ClickMax
ClickNum = ClickNum or 1

canvas = Canvas(Tk(), bg="white", bd=0, highlightthickn ess=0)
canvas.pack(fil l=BOTH, expand=YES)
drawline(0)
canvas.bind("<1 >", drawline)
canvas.mainloop ()

Eugene
"Ben Bush" <py*******@gmai l.com> wrote in message
news:ma******** *************** *************** *@python.org...
I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:
First, Clicknum increases when every time I click the button. Is it
possible to reset Clicknum to 0?
Second, how to do something like: I click the left button the first
time, the green line appear then disappear, the purple line
appear(just as the code has done but become a loop; if a second-time
click is implied, the loop stops.
from Tkinter import *

ClickNum = 0

def drawline(event) :
global ClickNum
if ClickNum == 0:
canvas.create_l ine(100, 0, 100, 200,
arrow=FIRST,fil l="green",tag=" a")
elif ClickNum == 1:
canvas.delete(" a")
canvas.create_l ine(100, 50, 60, 300, arrow=FIRST,fil l="purple")
ClickNum += 1

tk = Tk()
canvas = Canvas(tk, bg="white", bd=0, highlightthickn ess=0)
canvas.pack(fil l=BOTH, expand=YES)
canvas.create_l ine(100, 200, 350, 200, arrow=LAST,fill ='red')
canvas.bind("<1 >", drawline)
tk.mainloop()
Nov 23 '05 #2
Ben Bush wrote:
I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:


It's good that these postings are archived, so that teachers can
check them before grading their students. After all, the grades
belong to those who solved the problems, not to those who handed
them in...
Nov 23 '05 #3
On 11/23/05, Magnus Lycka <ly***@carmen.s e> wrote:
Ben Bush wrote:
I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:


It's good that these postings are archived, so that teachers can
check them before grading their students. After all, the grades
belong to those who solved the problems, not to those who handed
them in...

I learned Python by myself and not seeking to hand in these results
for anyone. All the questions are not from any textbook. Please be
polite and do not assume something just in your mind.
Nov 26 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
41410
by: Jon Cosby | last post by:
I'm using this to draw rectangles in a PictureBox image. Not all of the rectangles are complete, and after drawing several, some of them start disapearing. What's the reason for this? Pen selPen = new Pen(Color.White); Graphics graphic = this.PicBox.CreateGraphics(); ..................
1
2728
by: Rich | last post by:
Hello, I am trying to draw a graph on a form. I can draw the box using drawline, and bars inside the box using drawrectangle, but when I try to draw a line inside the box the inner lines are not showing up. Do I need to use a property or something? Here is the code for my lines
4
5762
by: Smoke | last post by:
It is possible to draw a line on a control using AA? basically, i need the normal .DrawLine funcion but that support antia aliasing. is this possible? can somebody tellme how? Thanks for the help, as usual
2
1951
by: google_groups3 | last post by:
Hi, is it better practise to draw a line on my form using the Graphics.DrawLine command or should I use a label control instead? I am refering to overall speed of the form and amount of memory used. TIA
2
3060
by: John | last post by:
I created a number of pictureboxes in a panel, and want to draw lines in those pictureboxes but I cannot. Please see the following code and make corrections. Thanks. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Panel1.AutoScroll = True Panel1.Width = 200 Panel1.Height = 200
0
1202
by: Lila Godel | last post by:
I am migrating my VB6 GoldMine add-ons to VB.NET to allow for enhancements. I have no problem getting text to print, but I cannot get the 4 PrintPage events that are needed to print a line to work. I need a line that has a width of 5 that starts 3.797 inches from the top edge of the paper, starts 0.613 inches from the left edge of the paper and ends at the edge of the paper so I know where to trim the paper for proper insertion in a form...
2
2664
by: Stu | last post by:
Hi, Why does the code below only draw the last line of the loop? I was expecting this to draw 10 parallel lines. More to the piont....how do I get it to draw 10 parallel lines? Public Function GetImage() As Bitmap Dim oBitmap As Bitmap = New Bitmap(200, 200) Dim oGraphic As Graphics = Graphics.FromImage(oBitmap) Dim oPen As New Pen(Color.Black, 4)
2
7165
by: intrepid_dw | last post by:
All I am writing a C# WinForms application which is giving me some problems. The application consists of a form containing an empty Tab control to which TabPages are added dynamically (at runtime). Each TabPage contains a single Panel control. My intent is to draw a graph on that Panel control dynamically, with the code capturing a point at each update interval, then calling the Graphics.DrawLine method of the panel
2
3419
by: RichGK | last post by:
This is from http://msdn2.microsoft.com/en-us/library/aa287522(VS.71).aspx public MainForm() { InitializeComponent(); System.Drawing.Pen myPen;
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.