Skip to content

Instantly share code, notes, and snippets.

@forrestwilkins
Created December 1, 2014 23:54
Show Gist options
  • Save forrestwilkins/30e43c25da7d9ebee849 to your computer and use it in GitHub Desktop.
Save forrestwilkins/30e43c25da7d9ebee849 to your computer and use it in GitHub Desktop.
from Tkinter import *
class Reservation(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, background="gray")
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Hotel Reservation")
# label definitions
self.contact_label = Label( self, text="Contact name")
self.phone_number_label = Label( self, text="Phone number")
self.credit_card_label = Label( self, text="Credit Card Number")
self.credit_card_civ_label = Label( self, text="CIV")
self.card_type_label = Label( self, text="Card type")
self.address_label = Label( self, text="Address (City, State, Zip)")
self.email_label = Label( self, text="Email")
self.room_type_label = Label( self, text="Room type")
# text box definitions
self.contact_text = Text(self, width=20, height=1)
self.phone_number_text = Text(self, width=12, height=1)
self.credit_card_text = Text(self, width=16, height=1)
self.credit_card_civ_text = Text(self, width=3, height=1)
self.address_text = Text(self, width=25, height=1)
self.email_text = Text(self, width=25, height=1)
# lisbox definitions
self.card_type_lb = Listbox(self, width=16, height=3)
card_types = ["Visa", "Master", "Discovery"]
for card_type in card_types:
self.card_type_lb.insert(END, card_type)
self.room_type_lb = Listbox(self, width=16, height=2)
room_types = ["Single, $49.99", "Double, $69.99"]
for room_type in room_types:
self.room_type_lb.insert(END, room_type)
# button definitions
self.button = Button(self, text="Enter", command=self.onClick)
# label placement
self.contact_label.place(x=50, y=50)
self.phone_number_label.place(x=50, y=125)
self.credit_card_label.place(x=50, y=200)
self.credit_card_civ_label.place(x=180, y=200)
self.address_label.place(x=50, y=325)
self.email_label.place(x=50, y=400)
self.room_type_label.place(x=250, y=50)
# text box placement
self.contact_text.place(x=50, y=75)
self.phone_number_text.place(x=50, y=150)
self.credit_card_text.place(x=50, y=225)
self.credit_card_civ_text.place(x=180, y=225)
self.address_text.place(x=50, y=350)
self.email_text.place(x=50, y=425)
# button placement
self.button.place(x=50, y=700)
# listbox placement
self.card_type_lb.place(x=50, y=250)
self.room_type_lb.place(x=250, y=75)
self.pack(fill=BOTH, expand=1)
self.centerWindow()
def onClick(self):
if self.text.get("1.0", END):
self.master.title(self.text.get("1.0", END))
def centerWindow(self):
w = 750
h = 750
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
x = (sw - w)/2
y = (sh - h)/2
self.parent.geometry('%dx%d+%d+%d' % (w, h, x, y))
def main():
root = Tk()
app = Reservation(root)
root.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment