本文整理汇总了Python中swampy.Gui.la方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.la方法的具体用法?Python Gui.la怎么用?Python Gui.la使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swampy.Gui
的用法示例。
在下文中一共展示了Gui.la方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Hwindow
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
class Hwindow():
"""Creates host/join menu."""
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 host(self):
"""Creates a game w/ 2 players and 2 computers."""
name = self.entryField.get()
data = {
'gameName': name
}
req = urllib2.Request('http://othello.herokuapp.com/createGame')
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps(data))
self.h.destroy() # close h window
os.system('python board_piece_final_tweaked1.py ' + name + ' black')
def join(self):
"""Joins an existing game w/ 2 players and 2 computers."""
name = self.entryField.get()
self.h.destroy() # close h window
os.system('python board_piece_final_tweaked1.py ' + name + ' white')
示例2: figure8
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
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()
示例3: Gui
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
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()
示例4: ab_app
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
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 ')
示例5: final_res
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
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)
示例6: ab_dev
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
def ab_dev():
abdev=Gui()
abdev.la(text='An app by Sujay HG')
示例7: res
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
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')
win.bu(text='View result analysis', command=res) #function res is invoked when the bu is clicked
win.endcol()
win.row([0,4], padx=1)
win.col()
bms=PIL.open('bmslogo.png')
示例8: Gui
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
"""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()
示例9: make_label
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
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()
示例10: Gui
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
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.")
la2 = g.la(text="")
def press_me():
"""this callback gets invoked when the user presses the button"""
text = en.get()
la2.configure(text=text)
# bu is for button
示例11: main
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
def main():
client = MongoClient()
db = client.test_database
users = db.users
users.remove()
print users
users.insert({'user':'hey', 'password':'there'})
for thing in users.find():
print thing
def newusergui():
def close():
signupgui.quit()
def newuser():
for user in users.find():
for info in user:
print info
print user[info]
if user[info]==newusername.get():
print 'already in use'
label.config(text="That username is already in use.")
return
if newpassword.get()==repeatnewpassword.get():
print 'running this loop'
users.insert({'user':newusername.get(), 'password': newpassword.get()})
print users
label.config(text="Thank you for signing up!")
close()
launch()
return True
else:
label.config(text="Your passwords don't match! Please try again")
usernamelabel=signupgui.la(text='Username:')
newusername=signupgui.en()
newpasswordlabel=signupgui.la(text='Password:')
newpassword=signupgui.en(show='*')
repeatpasswordlabel=signupgui.la(text='Re-enter Password')
repeatnewpassword=signupgui.en(show='*')
button=signupgui.bu(text="Let's get started!",command=newuser)
label=signupgui.la()
def logingui():
def close():
for user in users.find():
for info in user:
if password.get()==user[info]:
label.config(text= "You are now logged in!")
signupgui.quit()
launch()
return True
else:
label.config(text= "We do not recognize your username or password, please try again.")
usernamelabel=signupgui.la(text = "MusicSwAPPer Username: ")
username = signupgui.en()
passwordlabel=signupgui.la("MusicSwAPPer Password: ")
password = signupgui.en(show = '*')
button=signupgui.bu(text="Let's get started!",command=close)
label=signupgui.la()
signupgui=Gui()
signupgui.title('MusicSwAPPer Sign Up')
signuporlogin = signupgui.la(text = 'Please Sign-In or Sign-Up!')
signupgui.row()
login = signupgui.bu(text = 'Sign in', command=logingui)
sign = signupgui.bu(text = 'Sign up', command=newusergui)
signupgui.endrow()
signupgui.mainloop()
示例12: main
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
def main():
"""
Launches login system everytime the script is run, users have the option of signing in, or signing up if they have not already established an account and accout information. Upon login/signup, the main application is launched
"""
def newusergui():
"""
for anyone who needs to register, this adds them to the database system
"""
def newuser():
global username
for user in users.find():
for info in user:
if user[info]==newusername.get():
label.config(text="That username is already in use.")
return
if newpassword.get()==repeatnewpassword.get():
users.insert({'user':newusername.get(), 'password': newpassword.get()})
db.add_user(newusername.get(), newpassword.get())
label.config(text="Thank you for signing up!")
username = newusername.get()
launch()
else:
label.config(text="Your passwords don't match! Please try again")
usernamelabel=g.la(text='Username:')
newusername=g.en()
newpasswordlabel=g.la(text='Password:')
newpassword=g.en(show='*')
repeatpasswordlabel=g.la(text='Re-enter Password')
repeatnewpassword=g.en(show='*')
button=g.bu(text="Let's get started!",command=newuser)
label=g.la()
def logingui():
"""
this launches the general sign-in gui for those who have registered
"""
def close():
global username
for user in users.find():
if password.get()==user['password'] and usernameentry.get() == user['user']:
label.config(text= "You are now logged in!")
username = usernameentry.get()
g.quit()
launch()
return True
else:
label.config(text= "We do not recognize your username or password, please try again.")
usernamelabel=g.la(text = "MusicSwAPPer Username: ")
usernameentry = g.en()
passwordlabel=g.la("MusicSwAPPer Password: ")
password = g.en(show = '*')
button=g.bu(text="Let's get started!",command=close)
label=g.la()
g=Gui()
g.title('Launch MusicSwAPPer')
signuporlogin = g.la(text = 'Please Sign-In or Sign-Up!')
g.row()
login = g.bu(text = 'Sign in', command=logingui)
sign = g.bu(text = 'Sign up', command=newusergui)
g.endrow()
g.mainloop()
示例13: launch
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
def launch():
"""
launches the 'real' gui system, the one we interact with
"""
#names new databases that we will use now that the application is launched
share_hist = db.share_hist
display = db.display
point_total = db.point_total
shared_source = db.shared_source
shared_viewer = db.shared_viewer
#clears the databases upon running script
#IMPORTANT: leave the shared_viewer.remove()
shared_viewer.remove()
def initialize():
"""
upon running the script, gets data from the database and updates the gui displays
"""
global count
global share_count
global username
try:
for thing in point_total.distinct(username):
amount = thing
points.config(text = str(amount))
except:
point_total.insert({username:10})
for thing in point_total.distinct(username):
amount = thing
points.config(text = str(amount))
for thing in display.distinct(username):
share_history.canvas.text([0,count], text = thing['friend'] + ' ' + thing['share'] + ' ' + str(thing['date']))
count -= 12
for thing in shared_viewer.distinct(username):
link = new_shared_list.canvas.text([0,share_count], text = str(thing[username]['link']), activefill = 'blue')
link.bind('<Double-1>', onObjectClick)
share_count -= 12
def update():
"""
when the update button is pushed, this looks at the database, and will print things not already in the display, as well as log displayed data (meaning that if the gui closes before update is pressed, the data is still saved, and will be displayed the next time update will be pressed)
"""
global count
global username
for log in share_hist.find():
if log not in display.find():
display.insert(log)
share_history.canvas.text([0,count], text = log[username]['friend'] + ' ' + log[username]['share'] + ' ' + str(log[username]['date']))
count -= 12
get_new_shares()
def print_entry():
"""
Allows shares to be made, will check to make sure nothing is a repeat, will log the data. Interactive with the user.
"""
global count
global username
res = []
text = en.get()
connection = friend.get()
for user in users.find():
res.append(user['user'])
if connection not in res:
label.config(text = 'Sorry, user not in our records')
return
follower = ' was shared with '
message = text + follower + connection + '!'
for thing in point_total.distinct(username):
existing = thing
point_total.update({username: existing}, {'$inc': {username:(-1)}})
points.config(text = str(existing-1))
if count == 1:
t = datetime.datetime.now()
if t.minute < 10:
minute = '0'+str(t.minute)
else:
minute = str(t.minute)
timestamp = str(t.month) + '/' + str(t.day) +'/' + str(t.year) + ',' +str(t.hour) + ':' + minute
share_hist.insert({username:{'friend':connection,'share':text, 'date': timestamp}})
shared_source.insert({connection:{'link': text, 'friend':username}})
label.config(text = message)
count -= 12
else:
instance_count = 0
for instance in share_hist.distinct(username):
if text == instance['share'] and connection == instance['friend']:
label.config(text = 'That is a repeat!')
return
instance_count += 1
if instance_count == len(share_hist.distinct(username)):
t = datetime.datetime.now()
if t.minute < 10:
minute = '0'+str(t.minute)
else:
#.........这里部分代码省略.........
示例14: Gui
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
"""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
import ImageTk
image = PIL.open('allen.png')
photo2 = ImageTk.PhotoImage(image)
g.la(image=photo2)
g.mainloop()
示例15: url_display
# 需要导入模块: from swampy import Gui [as 别名]
# 或者: from swampy.Gui import la [as 别名]
index = event.widget.find_closest(event.x, event.y)
i = shared_viewer.find()
access = i[index[0] - 1]
link = access['link']
url_display(link)
shared_viewer.remove(access)
shared_source.remove(access)
#General set-up
g.title('Minumum Deliverable URLSender')
g.row()
g.col()
g.la(text = 'Welcome to musicswAPPer')
g.bu(text = 'Update Data', command = MediaShare.update())
g.row([0,1], pady = 10)
g.endrow()
g.la(text = 'Share a link!')
friend = g.en(text = 'Who do you want to share with?')
en = g.en(text = 'Insert URL here')
g.bu(text = 'Share', command = MediaShare.print_entry())
label = g.la()
g.row([0,1], pady = 10)
g.endrow()
g.la(text = 'Share History')
share_history = g.sc(width = 500, height = 300)
share_history.canvas.configure(confine = False, scrollregion = (0,0,1000,1000))