コード例 #1
0
# end of the first frame
g.endcol()

# FRAME 2

g.col()

# ca is for canvas
ca = g.ca(width=200, height=200)

item1 = ca.circle([0, 0], 70, 'red')
item2 = ca.rectangle([[0, 0], [60, 60]], 'blue')
item3 = ca.text([0, 0], 'This is a canvas.', 'white')

# mb is for menubutton
mb = g.mb(text='Choose a color')


def set_color(color):
    ca.itemconfig(item2, fill=color)


# mi is for menuitem
for color in ['red', 'green', 'blue']:

    # Callable is an object that can be used like a function
    g.mi(mb, color, command=Callable(set_color, color))

g.endcol()

# FRAME 3
コード例 #2
0
from swampy.Gui import *

g = Gui()
g.title('')
g.la('Select a color:')
colors = ['red', 'green', 'blue']
mb = g.mb(text=colors[0])


def set_color(color):
    print color
    mb.config(text=color)


for color in colors:
    g.mi(mb, text=color, command=Callable(set_color, color))

g.mainloop()
コード例 #3
0
ファイル: widget_demo.py プロジェクト: Ehsan1981/ThinkPython
g.endcol()


# FRAME 2

g.col()

# ca is for canvas
ca = g.ca(width=200, height=200)

item1 = ca.circle([0, 0], 70, "red")
item2 = ca.rectangle([[0, 0], [60, 60]], "blue")
item3 = ca.text([0, 0], "This is a canvas.", "white")

# mb is for menubutton
mb = g.mb(text="Choose a color")


def set_color(color):
    ca.itemconfig(item2, fill=color)


# mi is for menuitem
for color in ["red", "green", "blue"]:

    # Callable is an object that can be used like a function
    g.mi(mb, color, command=Callable(set_color, color))

g.endcol()

コード例 #4
0
ファイル: menubutton_demo.py プロジェクト: ANB2/ThinkPython
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com

Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

"""

from swampy.Gui import *

g = Gui()
g.title('')
g.la('Select a color:')
colors = ['red', 'green', 'blue']
mb = g.mb(text=colors[0])

def set_color(color):
    print color
    mb.config(text=color)

for color in colors:
    g.mi(mb, text=color, command=Callable(set_color, color))

g.mainloop()
コード例 #5
0
from swampy.Gui import *


def set_color(color):
    mb.config(text=color)
    print color


g = Gui()
g.title('Menubutton Demo')
g.la('Select a color:')
colors = ['red', 'green', 'blue']
mb = g.mb(text='color')

for color in colors:
    g.mi(mb, text=color, command=Callable(set_color, color))

g.mainloop()