[Tutor] Few simple question

Pijus Virketis virketis@fas.harvard.edu
Thu, 03 May 2001 00:06:23 -0400


--=====================_204520498==_.ALT
Content-Type: text/plain; charset="us-ascii"

All the tasks you described can be accomplished with a GUI creation module
called Tkinter, which interfaces to the Tk GUI library. A tutorial can by
found
here: http://www.pythonware.com/library/tkinter/introduction/. 

>1) I want to know how to change colour, i mean how to used colour in 
>python language.

Most Tkinter widgets take a argument  background or foreground. As in: 

label = Label(root, text="It's just an example", background = "red")

This will create a red field with the black letters "It's just an example" on
it.

>2). How to used coordinate system, or may be there is a module i can =
>used to help me. For example on the computer screen at a location =
>row=3D5, column 35, I want to print 'Hello world'. How to do that.

A widget called Canvas handles all the drawing in Tk. Here's the passage from
the tutorial about the coordinate system there:

"The Canvas widget uses two coordinate systems; the window coordinate system
(with (0, 0) in the upper left corner), and a canvas coordinate system in
which
the items are drawn. By scrolling the canvas, you can specify which part of
the
canvas coordinate system to show in the window."

If you just want to print things out on a screen, that's a bit different. You
can simple use the Label widget, as shown above, and then grid() it to your
needed location. So:

label = Label(root, text="Hello world", background = "red", font="Times 20")
label.grid(row=35, column=35)

>3). How to create box and how place it on the computer screen on the =
>desirerable location.

If you want to create a box, first you need to initialise a root window and
pack a Canvas widget in it:

root = Tk()
c = Canvas(root)
c.pack()

and then you can just create a box in your canvas:

c.create_rectangle(10,10,200,200, fill="red")

This will create a red rectange within the "box" of the specified size. In our
case, the rectangle and box are equivalent. But if you were creating an oval
shape, then the "box" would bound the oval's dimensions. 

Hope this helps.

Pijus 





----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis. 
--=====================_204520498==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
All the tasks you described can be accomplished with a GUI creation
module called Tkinter, which interfaces to the Tk GUI library. A tutorial
can by found here:
<a href="http://www.pythonware.com/library/tkinter/introduction/" eudora="autourl">http://www.pythonware.com/library/tkinter/introduction/</a>.
<br>
<br>
&gt;1) I want to know how to change colour, i mean how to used colour in
<br>
&gt;python language.<br>
<br>
Most Tkinter widgets take a argument&nbsp;
<font face="Courier New, Courier">background
</font>or<font face="Courier New, Courier"> foreground. </font>As
in:<font face="Courier New, Courier"> <br>
<br>
</font>label = Label(root, text=&quot;It's just an example&quot;,
background = &quot;red&quot;)<br>
<br>
This will create a red field with the black letters &quot;It's just an
example&quot; on it.<br>
<br>
&gt;2). How to used coordinate system, or may be there is a module i can
=<br>
&gt;used to help me. For example on the computer screen at a location
=<br>
&gt;row=3D5, column 35, I want to print 'Hello world'. How to do
that.<br>
<br>
A widget called Canvas handles all the drawing in Tk. Here's the passage
from the tutorial about the coordinate system there:<br>
<br>
&quot;The <font face="Courier New, Courier">Canvas widget uses two
coordinate systems; the window coordinate system (with (0, 0) in the
upper left corner), and a canvas coordinate system in which the items are
drawn. By scrolling the canvas, you can specify which part of the canvas
coordinate system to show in the window.</font>&quot;<br>
<br>
If you just want to print things out on a screen, that's a bit different.
You can simple use the Label widget, as shown above, and then grid() it
to your needed location. So:<br>
<br>
label = Label(root, text=&quot;Hello world&quot;, background =
&quot;red&quot;, font=&quot;Times 20&quot;)<br>
label.grid(row=35, column=35)<br>
<br>
&gt;3). How to create box and how place it on the computer screen on the
=<br>
&gt;desirerable location.<br>
<br>
If you want to create a box, first you need to initialise a root window
and pack a Canvas widget in it:<br>
<br>
root = Tk()<br>
c = Canvas(root)<br>
c.pack()<br>
<br>
and then you can just create a box in your canvas:<br>
<br>
c.create_rectangle(10,10,200,200, fill=&quot;red&quot;)<br>
<br>
This will create a red rectange within the &quot;box&quot; of the
specified size. In our case, the rectangle and box are equivalent. But if
you were creating an oval shape, then the &quot;box&quot; would bound the
oval's dimensions. <br>
<br>
Hope this helps.<br>
<br>
Pijus <br>
<br>
<br>
<br>
<br>
<br>
<div>-----------------------------------------------------------------------------------------------</div>
Please have a look at my weblog at
<a href="http://www.fas.harvard.edu/~virketis" EUDORA=AUTOURL>www.fas.harvard.edu/~virketis</a>.
</html>

--=====================_204520498==_.ALT--