def make_gui(): global g g = Gui() g.title('Chapter 19 Section 2 Excercise 1')
def make_gui(): global g g = Gui() g.title('Chapter 19 Section 5 Excercise 3') global canvas canvas = g.ca(width=500, height=500) canvas.config(bg='black')
def test_options(self): d = dict(a=1, b=2, c=3) res = Gui.pop_options(d, ['b']) self.assertEqual(len(res), 1) self.assertEqual(len(d), 2) res = Gui.get_options(d, ['a', 'c']) self.assertEqual(len(res), 2) self.assertEqual(len(d), 2) res = Gui.remove_options(d, ['c']) self.assertEqual(len(d), 1) d = dict(side=1, column=2, other=3) options, packopts, gridopts = Gui.split_options(d) self.assertEqual(len(options), 1) self.assertEqual(len(packopts), 1) self.assertEqual(len(gridopts), 1) Gui.override(d, side=2) self.assertEqual(d['side'], 2) Gui.underride(d, column=3, fill=4) self.assertEqual(d['column'], 2) self.assertEqual(d['fill'], 4)
def figure9(): print 'Figure 17.7 a' g = Gui() options = dict(side=LEFT) b1 = g.bu(text='OK', command=g.quit, **options) b2 = g.bu(text='Cancel', **options) b3 = g.bu(text='Help', **options) g.geometry('300x150') g.mainloop()
def figure7(): print 'Figure 17.5' g = Gui() options = dict(side=TOP, fill=X) b1 = g.bu(text='OK', command=g.quit, **options) b2 = g.bu(text='Cancel Command', **options) b3 = g.bu(text='Help', **options) g.mainloop() g.destroy()
def __init__(self): self.g = Gui() # make g window self.g.title('Othello!') self.g.gr(cols=2) localButton = self.g.bu(text='Local Game', command=self.local) internetButton = self.g.bu(text='Internet Game', command=self.internet) self.g.mainloop()
def test_canvas(self): gui = Gui.Gui() ca = gui.ca() self.assertEqual(ca.width, 100) self.assertEqual(ca.height, 100) point = [50, 50] box = [[100, 200], [300, 500]] item = ca.arc(box) self.assertTrue(isinstance(item, Gui.Item)) item = ca.line(box) self.assertTrue(isinstance(item, Gui.Item)) item = ca.oval(box) self.assertTrue(isinstance(item, Gui.Item)) item = ca.circle(point, 25) self.assertTrue(isinstance(item, Gui.Item)) item = ca.polygon(box) self.assertTrue(isinstance(item, Gui.Item)) item = ca.rectangle(box) self.assertTrue(isinstance(item, Gui.Item)) item = ca.text(point, 'text') self.assertTrue(isinstance(item, Gui.Item))
def __init__(self): self.h = Gui() # make h window self.h.title('Othello!') self.h.la(text='Game Name (no spaces)') self.entryField = self.h.en() self.h.gr(cols=2) hostButton = self.h.bu(text='Host Game', command=self.host) joinButton = self.h.bu(text='Join Game',command=self.join) self.h.mainloop()
def figure1(): print 'Figure 17.3 a' g = Gui() b1 = g.bu(text='OK', command=g.quit) b2 = g.bu(text='Cancel') b3 = g.bu(text='Help') g.mainloop()
def test_bbox(self): bbox = Gui.BBox([[100, 200], [300, 500]]) self.assertEqual(bbox.left, 100) self.assertEqual(bbox.right, 300) self.assertEqual(bbox.top, 200) self.assertEqual(bbox.bottom, 500) self.assertEqual(bbox.width(), 200) self.assertEqual(bbox.height(), 300) # TODO: upperleft, lowerright, midright, midleft, center, union t = bbox.flatten() self.assertEqual(t[0], 100) pairs = [pair for pair in Gui.pairiter(t)] self.assertEqual(len(pairs), 2) seq = Gui.flatten(pairs) self.assertEqual(len(seq), 4)
def figure4(): print 'Figure 17.4 a' g = Gui() options = dict(side=LEFT, padx=10, pady=10) b1 = g.bu(text='OK', command=g.quit, **options) b2 = g.bu(text='Cancel', **options) b3 = g.bu(text='Help', **options) g.mainloop()
def __init__(self, myMap = None, title = None, *colors): if myMap == None: self._map = getDefaultPBNMap() elif isinstance(myMap, PBNMap): self._map = myMap else: raise TypeError("myMap must be a PBN map or None") self._viewMap = PBNMap(self._map.dims()) self._colors = ["white", "black"] + [c for c in colors] + ["x"] self._gui = Gui() ##From Swampy self._view = PBNViewController(self._map.dims(), self._gui, title, *colors) self._view.setup([self.getRowList(i) for i in range(self._map.dims()[0])], [self.getColList(j) for j in range(self._map.dims()[0])], self._viewMap, self._controller)
def test_gui(self): gui = Gui.Gui() fr = gui.fr() endfr = gui.endfr() self.assertEqual(gui, endfr) row = gui.row() gui.rowweights([1, 2, 3]) col = gui.col() gui.colweights([1, 2, 3]) popfr = gui.popfr() self.assertEqual(popfr, row) en = gui.en() ca = gui.ca() self.assertTrue(isinstance(ca, Gui.GuiCanvas)) la = gui.la() widget = gui.la() widget = gui.lb() widget = gui.bu() mb = gui.mb() widget = gui.mi(mb) widget = gui.te() widget = gui.sb() widget = gui.cb() size = tkinter.IntVar() widget = gui.rb(variable=size, value=1) widget = gui.st() self.assertTrue(isinstance(widget, Gui.Gui.ScrollableText)) widget = gui.sc() self.assertTrue(isinstance(widget, Gui.Gui.ScrollableCanvas)) gui.destroy()
"""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('') def callback1(): g.bu(text='Now press me.', command=callback2) def callback2(): g.la(text='Nice job.') g.bu(text='Press me.', command=callback1) g.mainloop()
###For Randomizing Text Questions### list2=[1,2,3,4,5,6,7,8,9,0] global presuf presuf=sample(list2, 4)[:] r=randint(1,2) if r==1: ques_pos() elif r==2: ques_neg() def close(event=NONE): if tkMessageBox.askyesno("Quit","Do You Want To Quit???"): p.destroy() p=Gui() p.title('Sentiment Analysis') p.geometry(newGeometry='700x500') fr=p.fr() canint=p.ca(bg='green') imag=Image.open('pic1.jpg') imag2=ImageTk.PhotoImage(imag) canint.image([300,-200],image=imag2) canint.image=imag2 var=IntVar(0) var2=IntVar(0) but1=p.bu('YES',command=start,font=('bold',15), bg='red', fg='white', activebackground='white',activeforeground='red',bd=8).place(x=175,y=370, height=50, width=80) p.bind('y',start) but2=p.bu('NO',command=close,font=('bold',15), bg='red', fg='white', activebackground='white',activeforeground='red',bd=8).place(x=450,y=370, height=50, width=80) item1=canint.create_text(350,140,text="\nWelcome!!!\n Hope You Had A Great Day Till Now.\nIf Not, We Are Gonna Make It Great With This Program!!!\n\n\nSo Shall We Begin???",font=('BOOKMAN OLD STYLE',17,'bold'),justify=CENTER,fill='white')
from swampy.Gui import * import Tkinter import Image as PIL import ImageTk g = Gui() g.title('Image Viewer') canvas = g.ca(width = 400, height = 400) photo = Tkinter.PhotoImage(file = 'danger.gif') ''' PhotoImage reads a file and returns a PhotoImage object that Tkinter can display ''' canvas.image([0,0], image = photo) g.la(image = photo) g.bu(image = photo) g.mainloop()
"""Exercise 2 Write a program that creates a Canvas and a Button. When the user presses the Button, it should draw a circle on the canvas.""" from swampy.Gui import * g = Gui() g.title = "Gui" def make_circle(): canvas.circle([0, 0], 55, fill="orange", outline="white", width=3) canvas = g.ca(500, 500, bg="black") g.bu(text="make me a circle", command=make_circle) g.mainloop()
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html This program requires Gui.py, which is part of Swampy; you can download it from thinkpython.com/swampy. This program demonstrates how to use the Gui module to create and operate on Tkinter widgets. The documentation for the widgets is at http://www.pythonware.com/library/tkinter/introduction/ """ from swampy.Gui import * # create the Gui: the debug flag makes the frames visible g = Gui(debug=False) # the topmost structure is a row of widgets g.row() # FRAME 1 # the first frame is a column of widgets g.col() # la is for label la1 = g.la(text="This is a label.") # en is for entry en = g.en() en.insert(END, "This is an entry widget.")
# see how far we have moved # dx = event.x - self.dragx # dy = event.y - self.dragy pos = ca.canvas_coords([[self.dragx, self.dragy], [event.x, event.y]]) print pos item = ca.rectangle(pos, fill="red") # move the item # self.move(dx, dy) def drop(self, event): """Drops this item.""" self.config(fill=self.fill) g = Gui() ca = g.ca(width=500, height=500, bg="white") item = ca.rectangle([[-250, -250], [100, 100]], fill="red") vec = Vector(item) ca.bind("<ButtonPress-1>", vec.select) def make_circle(event): """Makes a circle item at the location of a button press.""" dx = event.x dy = event.y pos = ca.canvas_coords([[event.x, event.y], [event.x + 10, event.y + 10]]) print pos item = ca.rectangle(pos, fill="red")
from swampy.Gui import * from Tkinter import PhotoImage import PIL.Image import PIL.ImageTk g = Gui() canvas = g.ca(width=300) photo = PhotoImage(file='danger.gif') canvas.image([0,0], image=photo) g.la(image=photo) g.bu(image=photo) image = PIL.Image.open('allen.png') photo2 = PIL.ImageTk.PhotoImage(image) g.la(image=photo2) g.mainloop()
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()
from swampy.Gui import * g = Gui() g.title('') def callback1(): g.bu(text='Now press me.', command=callback2) def callback2(): g.la(text='Nice job.') g.bu(text='Press me.', command=callback1) g.mainloop()
#!/usr/bin/env python from swampy.Gui import * def make_label(): g.la(text='Good Job!') def make_button(): g.bu(text='Next', command=make_label) g = Gui() g.title('Gui') button1 = g.bu(text="Press Me", command=make_button) g.mainloop()
#!/usr/bin/env python from swampy.Gui import * def make_circle(): circle = canvas.circle([0,0], 100, fill='red') entry = g.en(text='Enter Color') button2 = g.bu(text='Enter', command=change_color) global circle, entry # handle the exception of changing color on a circle not created by # the order of operations, i.e. does not get to the color change until circle is created. def change_color(): color = entry.get() colorList = ['white', 'black', 'red', 'green', 'blue', 'cyan', 'yellow', 'magenta'] if color not in colorList: print "The color you specified is not valid. Available colors are: " for i in colorList: print i else: circle.config(fill=color) g = Gui() g.title('Gui') canvas = g.ca(width=500, height=500) canvas.config(bg='white') button1 = g.bu(text="Make Circle", command=make_circle) g.mainloop()
"""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()
import os from swampy.Gui import * import Tkinter import Image as PIL import ImageTk g = Gui() g.title('Image Viewer') canvas = g.ca(width=500, height=500, bg='white') def walk(dirname): for name in os.listdir(dirname): path = os.path.join(dirname, name) if os.path.isfile(path): try: show_image(name) print name g.mainloop() except: pass else: walk(path) def show_image(fp): image = PIL.open(fp) tkpi = ImageTk.PhotoImage(image) canvas(image=tkpi)
self.dragy = event.y self.move(dx, dy) def drop(self, event): self.config(fill=self.fill) def make_circle(event): pos = ca.canvas_coords([event.x, event.y]) item = ca.circle(pos, 5, fill='white') Draggable(item) def make_text(event=None): text = en.get() item = ca.text([0,0], text) Draggable(item) g = Gui() g.title('Draggable Demo') ca = g.ca(width=500, height=500, bg='black') ca.bind('<ButtonPress-3>', make_circle) g.row([1,0]) en = g.en() bu = g.bu('Make text item:', make_text) en.bind('<Return>', make_text) g.mainloop()
def final_res(ipusn): view=Gui() view.title('view results') fin=open('RES.txt') usn_gpa={} #an dictionary with usn as key and gpa as items name_usn={} gpa_usn={} #an dictionary with gpa as key and usn as items linesplit=[] #an empty list gpaacc=[] #a list to store all the gpas usnacc=[] #a list to store all the usn usn_name={} #a dictionary to map usn to names for line in fin: linesplit=line.split(' ') #reads the line and splits it into list of strings gpa=gpa_calc(linesplit) #sends the whole list to the function usn_gpa[linesplit[1]]=gpa #stores the gpa in a dictionary database usnacc.append(linesplit[1]) #stores the usn into a usn accumilator dell=' ' usn_name[linesplit[1]]=dell.join(linesplit[2:-18]) #extracts the name from the line if gpa in gpa_usn: #store all the usns with same GPAs under the GPA key gpa_usn[gpa].append(linesplit[1]) else: gpa_usn[gpa]=[linesplit[1]] if gpa not in gpaacc: #store gpa into gpaacc if it is not in the list gpaacc.append(gpa) gpaacc.sort(reverse=True) #sort the gpa acc for finding the rank if ipusn not in usnacc: view.la(text='Invalid USN\n Make sure you have entered the USN correctly') gpa2=usn_gpa[ipusn] #get the gpa of the student whose usn is taken as input for i in range(len(gpaacc)): #find the rank if gpaacc[i]==gpa2: rank=i+1 view.row() view.col() view.la(text='Hello %s' %usn_name[ipusn]) view.la(text='Your SGPA is %s' %gpa2) view.la(text='Your SGPA position is %i: ' %rank) view.endcol() gpa_usn[gpa2].remove(ipusn) view.col(padx=50) view.la(text='Your SGPA is tied with %s students' %len(gpa_usn[gpa2])) view.col(pady=50) view.col(padx=5) for u in gpa_usn[gpa2]: var='%s (%s)' %(usn_name[u], u) view.la(text=var) view.col(pady=5)
def ab_app(): abapp=Gui() abapp.row([0,1]) abapp.la(text='This is an app developed to analyse the results of \n BMS College of Engineering, Grading system ')
from swampy.Gui import * g = Gui() g.title("Gui") text = g.te(width=100, height=5) canvas = g.ca(width=300, height=300) canvas.config(bg='grey') circle = None def change_color(): global circle color = entry.get() print color if circle == None: return circle.config(fill=color) def draw_circle(): global circle circle = canvas.circle([0, 0], 100, fill='red') g.bu(text='create circle', command=draw_circle) entry = g.en() g.bu(text='change color', command=change_color) g.mainloop()
from swampy.Gui import * g = Gui() g.title = "Gui" def make_circle(): canvas.circle([0, 0], 55, fill="orange", outline="white", width=3) canvas = g.ca(500, 500, bg="black") g.bu(text="make me a circle", command=make_circle) g.mainloop()
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html This program requires Gui.py, which is part of Swampy; you can download it from thinkpython.com/swampy. This program demonstrates how to use the Gui module to create and operate on Tkinter widgets. The documentation for the widgets is at http://www.pythonware.com/library/tkinter/introduction/ """ from swampy.Gui import * # create the Gui: the debug flag makes the frames visible g = Gui(debug=False) # the topmost structure is a row of widgets g.row() # FRAME 1 # the first frame is a column of widgets g.col() # la is for label la1 = g.la(text='This is a label.') # en is for entry en = g.en() en.insert(END, 'This is an entry widget.')
from swampy.Gui import * g = Gui() g.title('19-3.py') canvas = g.ca(width = 500, height = 600, bg = 'white') circle = None def make_circle(): circle = canvas.circle([0,0], 100) def make_change(): if circle == None: return color = entry.get() try: circle.config(fill = color) except TclError, message: print message b1 = g.bu(text = 'Create Circle', command = make_circle) entry = g.en() b2 = g.bu(text = 'Press to Config', command= make_change) g.mainloop()
from swampy.Gui import * import Tkinter import Image as PIL import ImageTk g = Gui() g.title('Image Viewer') canvas = g.ca(width=400, height=400) photo = Tkinter.PhotoImage(file='danger.gif') ''' PhotoImage reads a file and returns a PhotoImage object that Tkinter can display ''' canvas.image([0, 0], image=photo) g.la(image=photo) g.bu(image=photo) g.mainloop()
from swampy.Gui import * g = Gui() g.title("Gui") g.mainloop()
'''import urllib conn = urllib.urlopen('http://thinkpython.com/secret.html') for line in conn: print line.strip()''' from swampy.Gui import * g = Gui() g.title('Web Browser') canvas = g.ca(width=400, height=400) b1 = g.bu(text="Click to browse", command=make_change)
from swampy.Gui import * g = Gui() g.title('Button demo gui') #tao ra 1 canvas canvas = g.ca(width=250, height=250) canvas.config(bg='white') def draw_circle_in_canvas(): #cai tien ve hong tam item = canvas.circle([0, 0], 100, fill='red') item.config(fill='yellow', outline='red', width=15) item1 = canvas.circle([0, 0], 70, fill='red') item1.config(fill='yellow', outline='red', width=15) item2 = canvas.circle([0, 0], 40, fill='red') item2.config(fill='yellow', outline='red', width=15) item3 = canvas.circle([0, 0], 10, fill='red') item3.config(fill='yellow', outline='red', width=15) button = g.bu(text='First button', command=draw_circle_in_canvas) g.mainloop()
from swampy.Gui import * def make_label(): g.la(text='Thank you.') g = Gui() g.title('Gui') button = g.bu(text='Press me.') button2 = g.bu(text='No, press me!', command=make_label) label = g.la(text='Press the buttom.') canvas = g.ca(width=500, height=500) canvas.config(bg='white') item = canvas.circle([0,0], 100, fill='red') item.config(fill='yellow', outline='orange', width=10) canvas.rectangle([[0,0], [200,200]], fill='blue',outline='orange',width=10) canvas.oval([[0,0], [200,100]], outline='orange', width=10) canvas.line([[0,100], [100,200], [200,100]], width=10) canvas.polygon([[0,100], [100,200], [200,100]], fill='red', outline='orange', width=10) entry = g.en(text='Default text.') text = g.te(width=100, height=5) text.insert(END, 'A line of text.') text.insert(1.1, 'nother') text.delete(1.2, END) g.mainloop()
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()
"""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 * from tkinter import PhotoImage g = Gui() photo = PhotoImage(file='danger.gif') g.bu(image=photo) canvas = g.ca(width=300) canvas.image([0, 0], image=photo) from PIL import Image as PIL from PIL import ImageTk image = PIL.open('allen.png') photo2 = ImageTk.PhotoImage(image) g.la(image=photo2) g.mainloop()
def figure8(): print 'Figure 17.6' g = Gui() options = dict(side=TOP, fill=X) # create the widgets g.fr() la = g.la(side=TOP, text='List of colors:') lb = g.lb(side=LEFT) sb = g.sb(side=RIGHT, fill=Y) g.endfr() bu = g.bu(side=BOTTOM, text='OK', command=g.quit) # fill the listbox with color names colors = [] for line in open('/etc/X11/rgb.txt'): t = line.split('\t') name = t[-1].strip() colors.append(name) for color in colors: lb.insert(END, color) # tell the listbox and the scrollbar about each other lb.configure(yscrollcommand=sb.set) sb.configure(command=lb.yview) g.mainloop() g.destroy()
"""Solution to an exercise from Think Python: An Introduction to Software Design Copyright 2010 Allen B. Downey License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html This program requires Gui.py, which is part of Swampy; you can download it from thinkpython.com/swampy. """ import os, sys from swampy.Gui import * import Image as PIL # to avoid name conflict with Tkinter import ImageTk def show_image(filename): # tkpi has to be global because otherwise it gets # deallocated when the function ends. global tkpi image = PIL.open(filename) tkpi = ImageTk.PhotoImage(image) g.la(image=tkpi) g = Gui() show_image('allen.png') g.mainloop()
''' Exercise 2 Write a program that creates a Canvas and a Button. When the user presses the Button, it should draw a circle on the canvas. ''' from swampy.Gui import * g = Gui() g.title('Exercise 2') def cb1(): item = canvas.circle([0, 0], 100, fill='black', outline='white') button = g.bu(text='Draw Circle', command=cb1) canvas = g.ca(width=500, height=500) canvas.config(bg='black') g.mainloop()
"""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('circle demo') canvas = g.ca(width=500, height=500, bg='white') circle = None def callback1(): """called when the user presses 'Create circle' """ global circle circle = canvas.circle([0, 0], 100) def callback2(): """called when the user presses 'Change color' """ # if the circle hasn't been created yet, do nothing if circle is None: return # get the text from the entry and try to change the circle's color
def make_gui(): global g g = Gui() g.title('Chapter 19 Excercise 2')
view.la(text=var) view.col(pady=5) def res(): u=entry.get() #get the entry from the txt field(input USN) final_res(u.upper()) #pass the usn into the function win = Gui() #initialise a win object win.title('GPA Analysis') win.row() logo1=PIL.open('logo.png') logo=ImageTk.PhotoImage(logo1) win.la(image=logo) win.row([0,0], padx=50) win.la(text='Analysing 4th sem, ECE results \n of the year 2014') win.col() win.bu(text='About the app', command=ab_app) win.bu(text='About the Developer', command=ab_dev) win.la(text='Kindly mail your feedback to \n [email protected]') win.endcol() win.col([0,3],pady=70,padx=50) win.la(text='Enter your USN') entry=win.en(text='1BM12EC129')
def ab_dev(): abdev=Gui() abdev.la(text='An app by Sujay HG')
def callable3(): global circle circle = canvas.circle([0,0], 100, fill='white') def change_color(): if circle == None: return 'Create a circle before press button.' color = entry.get() try: circle.config(fill=color) except: message = 'probaly an unknown color name' print message g = Gui() g.title('Gui') button = g.bu(text='Press it', command=callback1) canvas = g.ca(width=500, height=500) circle = None #canvas.config(bg='black') #item = canvas.rectangle([[0, 0], [200, 200]], #fill='white', outline='orange',width=10) #item = canvas.oval([[0, 0], [200, 100]], #fill='white', outline='orange',width=10) #item = canvas.line([[0, 100], [100, 200], [200, 100]], width=10, fill='white') #item = canvas.polygon([[0, 100], [100, 200], [200, 100]], width=10, fill='white', outline='orange') #entry = g.en(text='Default text.') #print entry.get()
dy = event.y - self.dragy # save the current drag coordinates self.dragx = event.x self.dragy = event.y # move the item self.move(dx, dy) def drop(self, event): """Drops this item.""" self.config(fill=self.fill) # create the Gui and the Canvas g = Gui() ca = g.ca(width=500, height=500, bg='white') def make_circle(event): """Makes a circle item at the location of a button press.""" pos = ca.canvas_coords([event.x, event.y]) item = ca.circle(pos, 5, fill='red') item = Draggable(item) ca.bind('<ButtonPress-3>', make_circle) def make_text(event=None): """Pressing Return in the Entry makes a text item.""" text = en.get() item = ca.text([0,0], text) item = Draggable(item)
from swampy.Gui import * g = Gui() g.title = ('Gui')
"""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("circle demo") canvas = g.ca(width=500, height=500, bg="white") circle = None def callback1(): """called when the user presses 'Create circle' """ global circle circle = canvas.circle([0, 0], 100) def callback2(): """called when the user presses 'Change color' """ # if the circle hasn't been created yet, do nothing if circle == None: return # get the text from the entry and try to change the circle's color
from swampy.Gui import * from Tkinter import * g = Gui() g.title('Gui') class Canvas(): """ """ def __init__(self): canvas = g.ca(width=500, height=500) class MakeWindow(): """ """ def setup(self): self.canvas = g.ca(width=500, height=500, bg='white') def add_button(self, text, the_command=None): g.bu(text, command=the_command) #b.pack() def test_it(): print "yeah" # def set_option(self, color): # mb.config(text = option) # print color
#! /usr/bin/python from swampy.Gui import * def testBit(int_type, offset): mask = 1 << offset return(int_type & mask) def toggleBit(int_type, offset): mask = 1 << offset return(int_type ^ mask) model = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] g = Gui() g.title('Font creator') canvas = g.ca(200, 300, bg='orange') def redrawCanvas(): canvas.clear() for line in range(0, 16): canvas.text([70, 140-18*line], '['+str(line)+']='+str(model[line])) for pos in range(0, 8): x = 40 - pos * 10 y = 80 - line * 10 item = canvas.rectangle([[x, y], [x+10, y+10]], fill='white', outline='black', width=1) if testBit(model[line], pos) > 0: item.config(fill='black') def mouseClicked(event): cc = canvas.canvas_coords([event.x, event.y])