Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1)
- import Tkinter
- win = Tkinter.Tk()
- win.title('Converter')
- def convert():
- st = fEntry.get()
- v = eval(st)
- if type(v) != type('Hello'):
- vLabel.config(text=str(v*.3048),justify='right')
- def convert2():
- st=fEntry.get()
- v=eval(st)
- if type(v)!=type('hello'):
- vLabel.config(text=str(v*3.2808),justify='right')
- def swap():
- fLabel.config(text='Meters')
- mLabel.config(text='Feet ')
- cb.config(command=convert2)
- sb.config(command=swap2)
- def swap2():
- fLabel.config(text='Feet ')
- mLabel.config(text='Meters')
- cb.config(command=convert)
- sb.config(command=swap)
- label = Tkinter.Label(win,text="Convert Feet to Meters",font=('Courier New',30,'bold'))
- label.pack()
- Row2 = Tkinter.Frame(win)
- fLabel = Tkinter.Label(Row2,text='Feet ',font=('Courier New',30))
- fEntry = Tkinter.Entry(Row2,width=12,bd=4,relief='raised',font=('Courier New',30))
- fLabel.pack(side='left')
- fEntry.pack(side='left')
- Row2.pack()
- Row3 = Tkinter.Frame(win)
- mLabel = Tkinter.Label(Row3,text='Meters',font=('Courier New',30))
- vLabel = Tkinter.Label(Row3,width=12,bd=4,relief='raised',text=' ',font=('Courier New',30))
- mLabel.pack(side='left')
- vLabel.pack(side='left')
- Row3.pack()
- Row4 = Tkinter.Frame(win)
- qb = Tkinter.Button(Row4,text='Quit',command=win.destroy,font=('Courier New',30))
- cb = Tkinter.Button(Row4,text='Convert',command=convert,font=('Courier New',30))
- sb = Tkinter.Button(Row4,text='Swap',command=swap,font=('Courier New',30))
- qb.pack(side='left')
- cb.pack(side='left')
- sb.pack(side='left')
- Row4.pack()
- win.mainloop()
- 2)
- from Tkinter import *
- import random
- win = Tk()
- win.title('Dragon Realm')
- win.geometry("%dx%d%+d%+d"%(700,500,0,50))
- f = ('Courier New',30)
- fb = f + ('bold',)
- def pbc():
- global gameState, userSel, GoodCave, Pic, Cap
- if gameState == 0:
- gameState = 1
- stateDisp(1)
- elif gameState == 2:
- gameState = 3
- if userSel == GoodCave:
- Pic = gDragon
- Cap = "Gives you his treasure!"
- stateDisp (1)
- else:
- Pic = bDragon
- Cap = "Gobbles you down in one bite!"
- stateDisp(3)
- elif gamestate == 3:
- gamestate = 0
- stateDisp(0)
- stateDisp(3)
- def b1():
- global gameState, userSel
- if gameState == 1:
- userSel = 1
- gameState = 1
- stateDisp(2)
- def b2():
- global gameState, userSel
- if gameState == 1:
- userSel = 2
- gameState = 2
- stateDisp(2)
- def Spacer():
- return Label(win,text=' ',font=f)
- introStr = """
- You are on a planet
- full of dragons.
- In front of you
- are two caves.
- In one cave,
- the dragon is friendly
- and will share his
- treasure with you.
- The other dragon is greedy
- and hungry, and will eat
- you on sight. If you
- decide to play you will
- have to choose one of
- the two caves to enter!
- """
- gameState = 0
- GoodCave = 0
- userSel = 0
- for i in range(7):
- Spacer().grid(row=0,column=i)
- Spacer().grid(row=2,column=i)
- Spacer().grid(row=5,column=i)
- Globe = PhotoImage(file='globe.gif')
- Lcave = PhotoImage(file='CaveLeft.gif')
- Rcave = PhotoImage(file='CaveRight.gif')
- bDragon = PhotoImage(file='bdragon.gif')
- gDragon = PhotoImage(file='gdragon.gif')
- qb = Button(win,text='QUIT',font=fb,command=win.destroy,width=12)
- qb.grid(row=4,column=3)
- pb = Button(win,text='PLAY',font=fb,width=12,command=pbc)
- pb.grid(row=3,column=3)
- c1b = Button(win,image=Globe,font=fb,command=b1)
- c2b = Button(win,image=Globe,font=fb,command=b2)
- c1b.grid(row=1,column=1)
- c2b.grid(row=1,column=5)
- cL = Label(win,text=introStr,justify='left',font=('Courier New',15))
- cL.grid(row=1,column=3)
- fPic = Label(win,image=Globe)
- capL = Label(win,text="Not Changed",font=fb)
- def stateDisp(s):
- global Pic, Cap, GoodCave
- if s == 0:
- fPic.grid_remove()
- capL.grid_remove()
- pb.config(text='PLAY')
- pb.grid(row=3,column=3)
- c1b.config(image=Globe)
- c1b.grid(row=1,column=1)
- c2b.config(image=Globe)
- c2b.grid(row=1,column=5)
- cL.config(text=introStr,font=('Courier New',18))
- cL.grid(row=1,column=3)
- GoodCave = random.randint(1,2)
- elif s == 1:
- pb.grid_remove()
- c1b.config(image=Lcave)
- c2b.config(image=Rcave)
- cL.config(text='Choose a Cave',font=fb)
- elif s == 2:
- c1b.grid_remove()
- c2b.grid_remove()
- cL.config(height=12)
- ttxt = """
- You approach the cave...
- It is dark and spooky...
- A large dragon jumps out in front of you!
- He opens his jaws and ...
- """
- cL.config(text=ttxt)
- pb.config(text='CONTINUE')
- pb.grid(row=3,column=3)
- elif s == 3:
- gameState = 0
- stateDisp(0)
- cL.grid_remove()
- fPic.config(image=Pic)
- fPic.grid(row=1,column=3)
- capL.config(text=Cap)
- capL.grid(row=0,column=3)
- pb.config(text='PLAY AGAIN')
- pb.config()
- stateDisp(0)
- win.mainloop()
- 3)
- from Tkinter import*
- import random
- class die():
- def __init__(self,parent,initVal):
- self.value= initVal
- self.display= Label(parent,text=str(self.value),font=('Courier New',30),relief='ridge',borderwidth=2)
- def roll(self):
- self.value= random.randint(1,6)
- self.display.config(text=str(self.value))
- hands = []
- win = Tk()
- win.title("Dice")
- win.geometry("%dx%d%+d%+d"%(700,300,0,50))
- dice = Frame(win)
- a=die(dice,1)
- b=die(dice,1)
- c=die(dice,1)
- d=die(dice,1)
- e=die(dice,1)
- a.display.pack(side='left')
- b.display.pack(side='left')
- c.display.pack(side='left')
- d.display.pack(side='left')
- e.display.pack(side='left')
- dice.pack()
- label= Label(win,text='5-of-a-kind ',font=('Courier New',30,'bold'))
- label.pack()
- l=[a,b,c,d,e]
- def Roll():
- hands = []
- for x in l:
- x.roll()
- for i in range (6):
- j = 0
- for y in l:
- if (y.value == (i + 1)):
- j = j + 1
- if (j > 1):
- hands.append(j)
- string = ''
- for x in hands:
- if (x == 2):
- string = string + "You have a pair.\n"
- else:
- string = string + "You have " + str(x) + " of a kind.\n"
- if (string == ''):
- label.config(text="You have nothing useful.\n")
- else:
- label.config(text=string)
- button_row = Frame(win)
- button = Button(button_row,text='Roll',command=Roll,font=('Courier New',30))
- button.pack(side='left')
- button_row.pack()
- win.mainloop()
- 4) I work with a few individuals to get this assignment done. Dylan Choquette helped me out a little and so didn’t Kelsie York. Ben Weeks is also in my hall so we finalized our work together. I have also been working with Lyle, Sam, and Teddy. Most importantly I used the slides and documents you posted on Blackboard.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement