Install Tkinter for Windows 7 64-bit
MRAB
python at mrabarnett.plus.com
Mon Nov 11 12:21:56 EST 2013
On 11/11/2013 16:43, jonas.thornvall at gmail.com wrote:
> 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()
More information about the Python-list
mailing list