Install Tkinter for Windows 7 64-bit


J

jonas.thornvall

I have installed Python 3.3, and i want to add a library with some basic functions like canvas and basic geomteric objects, fonts etc. Preferably something similar to the Javascript canvas.

I've looked for graphic packages, and from what i can see something called Tkinter may be what i look for.

However i have no luck install it, i installed something called Visual studio in hope it would incorporate Tkinter, but it did not and it also do not seem to work with 3.3 only 3.1 and below.

Next i found ActiveStateTCL that from what i could see incorporated Tkinter library?

But i have no luck runn the Tkinter example file i downloaded in idel, it still says no module called Tkinter.


===
Traceback (most recent call last):
File "D:\Python33\test2.py", line 16, in <module>
from Tkinter import Tk, Canvas, Frame, BOTH
ImportError: No module named 'Tkinter'
===

Maybe i should use some other module, i just need a canvas and the basic geometric objects functions line,rectangle,circle and some font.

JT
 
Ad

Advertisements

C

Chris “Kwpolska†Warrick

But i have no luck runn the Tkinter example file i downloaded in idel, itstill says no module called Tkinter. IDLE*
===
Traceback (most recent call last):
File "D:\Python33\test2.py", line 16, in <module>
from Tkinter import Tk, Canvas, Frame, BOTH
ImportError: No module named 'Tkinter'
===

In Python 3, 'Tkinter' was renamed to 'tkinter' (both sans quotes).
Please change the file to reflect that (as the traceback points out,
line 16).
 
J

jonas.thornvall

Here is the example file i have tried.

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
ZetCode Tkinter tutorial

This program draws three
rectangles filled with different
colors.

author: Jan Bodar
last modified: January 2011
website: www.zetcode.com
"""

from Tkinter import Tk, Canvas, Frame, BOTH


class Example(Frame):

def __init__(self, parent):
Frame.__init__(self, parent)

self.parent = parent
self.initUI()

def initUI(self):

self.parent.title("Colors")
self.pack(fill=BOTH, expand=1)

canvas = Canvas(self)
canvas.create_rectangle(30, 10, 120, 80,
outline="#fb0", fill="#fb0")
canvas.create_rectangle(150, 10, 240, 80,
outline="#f50", fill="#f50")
canvas.create_rectangle(270, 10, 370, 80,
outline="#05f", fill="#05f")
canvas.pack(fill=BOTH, expand=1)
 
T

Tim Golden

I have installed Python 3.3, and i want to add a library with some
basic functions like canvas and basic geomteric objects, fonts etc.
Preferably something similar to the Javascript canvas.

I've looked for graphic packages, and from what i can see something
called Tkinter may be what i look for.

However i have no luck install it, i installed something called
Visual studio in hope it would incorporate Tkinter, but it did not
and it also do not seem to work with 3.3 only 3.1 and below.

Next i found ActiveStateTCL that from what i could see incorporated
Tkinter library?

But i have no luck runn the Tkinter example file i downloaded in
idel, it still says no module called Tkinter.


=== Traceback (most recent call last): File "D:\Python33\test2.py",
line 16, in <module> from Tkinter import Tk, Canvas, Frame, BOTH
ImportError: No module named 'Tkinter' ===

Maybe i should use some other module, i just need a canvas and the
basic geometric objects functions line,rectangle,circle and some
font.

I'll let others comment on the use of Tk. But...

The Tkinter module has been reorganised under Python 3.x:

http://docs.python.org/3.3/library/tkinter.html#module-tkinter

You're presumably working from a Python 2.x example

TJG
 
T

Tim Golden

=== Traceback (most recent call last): File "D:\Python33\test2.py",
line 16, in <module> from Tkinter import Tk, Canvas, Frame, BOTH
ImportError: No module named 'Tkinter' ===

In addition, I really don't recommend running your test scripts straight
out of the Python install directory. Consider using a separate "dev"
area somewhere else.

TJG
 
J

jonas.thornvall

Den måndagen den 11:e november 2013 kl. 17:43:12 UTC+1 skrev Chris “Kwpolska” Warrick:
In Python 3, 'Tkinter' was renamed to 'tkinter' (both sans quotes).

Please change the file to reflect that (as the traceback points out,

line 16).



--

Chris “Kwpolska” Warrick <http://kwpolska.tk>

PGP: 5EAAEA16

stop html mail | always bottom-post | only UTF-8 makes sense

Thanks!
 
Ad

Advertisements

M

MRAB

Here is the example file i have tried.

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
ZetCode Tkinter tutorial

This program draws three
rectangles filled with different
colors.

author: Jan Bodar
last modified: January 2011
website: www.zetcode.com
"""

from Tkinter import Tk, Canvas, Frame, BOTH


class Example(Frame):

def __init__(self, parent):
Frame.__init__(self, parent)

self.parent = parent
self.initUI()

def initUI(self):

self.parent.title("Colors")
self.pack(fill=BOTH, expand=1)

canvas = Canvas(self)
canvas.create_rectangle(30, 10, 120, 80,
outline="#fb0", fill="#fb0")
canvas.create_rectangle(150, 10, 240, 80,
outline="#f50", fill="#f50")
canvas.create_rectangle(270, 10, 370, 80,
outline="#05f", fill="#05f")
canvas.pack(fill=BOTH, expand=1)
That looks like it was written for Python 2 because in Python 3 the
module is named "tkinter".

It's also lacking the part where it calls the .mainloop method.


from tkinter import Tk, Canvas, Frame, BOTH

class Example(Frame):

def __init__(self, parent):
Frame.__init__(self, parent)

self.parent = parent
self.initUI()

def initUI(self):

self.parent.title("Colors")
self.pack(fill=BOTH, expand=1)

canvas = Canvas(self)
canvas.create_rectangle(30, 10, 120, 80,
outline="#fb0", fill="#fb0")
canvas.create_rectangle(150, 10, 240, 80,
outline="#f50", fill="#f50")
canvas.create_rectangle(270, 10, 370, 80,
outline="#05f", fill="#05f")
canvas.pack(fill=BOTH, expand=1)

def main():

root = Tk()
# root.geometry("250x150+300+300")
app = Example(root)
root.mainloop()

if __name__ == '__main__':
main()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top