Advertisement
Guest User

Untitled

a guest
Nov 4th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.27 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import ttk
  3. import tkinter as tk
  4. from tkinter.messagebox import showinfo
  5. import tkinter.simpledialog
  6. import tkinter.messagebox
  7.  
  8. ################################################################################################################################################################################################
  9.  
  10. class Game:
  11. def __init__(self, name, rating, price, publisher, sale):
  12. self.name = name
  13. self.rating = rating
  14. self.price = price
  15. self.publisher = publisher
  16. self.sale = sale #will be used a mutliplier e.g. 0.6 x price, 1 x price (default)
  17. gameName.append(self)
  18. gameList.append(self.name)
  19. gamePrice.append(self.price)
  20.  
  21. ################################################################################################################################################################################################
  22.  
  23. class User:
  24. def __init__(self, username, password, balance, library):
  25. self.username = username
  26. self.password = password
  27. self.balance = balance
  28. self.library = library #this will be an array which will be added via, gta.name etc
  29. userList.append(self)
  30. userLib.append(self.library)
  31.  
  32. #############################################################################################################################################################################################
  33.  
  34. class Buying():
  35.  
  36. global selectedgame, sessionlibrary, sessionbalance, cart, checkout_price
  37. def __init__(self, *args): #REPEATED CODE IS NEEDED for some of the part,
  38. self.buywindow = Toplevel(root)
  39. self.buywindow.title("buy a game")
  40. self.buywindow.geometry('{}x{}'.format(500, 530))
  41. self.buywindow.resizable(0,0)
  42. self.buywindow.grab_set()#made it unclickable
  43. #########################
  44. labelCom = Label(self.buywindow, text="Purchase", font=("arial", 24), background="#999", width=10).grid(row=0, column=1, sticky=N, padx=6, pady=6)
  45. labelgame = Label(self.buywindow, text="game avaliable", font=("arial", 18)).grid(row=1, column=0, sticky=N, padx=6, pady=6)
  46. #labelCopies = Label(self.buywindow, text="how many copies", font=("arial", 18)).grid(row=2, column=0, sticky=N, padx=6, pady=6)
  47. ########################
  48. self.labelCartlist = StringVar()
  49. self.labelCartlist.set("cart list:")
  50. self.labelCartContent = Label(self.buywindow, textvariable=self.labelCartlist, font=("arial", 10)).grid(row=4, column=0, sticky=N, padx=6, pady=6)
  51. ########################
  52. labelremove = Label(self.buywindow, text="to remove from your cart", font=("arial", 10)).grid(row=4, column=1, sticky=N, padx=6, pady=6)
  53. ########################
  54. self.removeEntry = StringVar()
  55. self.removeEntry.trace("w", lambda name, index, mode, removeEntry=self.removeEntry: self.delete(self.removeEntry))
  56. self.removeEntrytext = Entry(self.buywindow, textvariable="", state='disabled')
  57. self.removeEntrytext.grid(row=5, column=1, padx=6, pady=6, ipadx=10, ipady=8)
  58. ########################
  59. self.removedbutton = Button(self.buywindow, text="remove from cart", command=self.delete, state="disabled")#changing test() to test make it so that a button is needed,
  60. self.removedbutton.grid(row=5, column=2)
  61. ########################
  62. self.labelCart = StringVar() ###### tempcart thingy
  63. self.labelCart.set("")
  64. self.labelCartContent = Label(self.buywindow, textvariable=self.labelCart, font=("arial", 10)).grid(row=5, column=0, sticky=N, padx=6, pady=6)
  65. ########################
  66. self.labelNoti = StringVar()
  67. self.labelNoti.set("")
  68. self.labelNotiContent = Label(self.buywindow, textvariable=self.labelNoti, font=("arial", 8)).grid(row=3, column=0, sticky=N, padx=6, pady=6)
  69. ########################
  70. self.labelPrice = StringVar()
  71. self.labelPrice.set("$0")
  72. self.labelPriceContent = Label(self.buywindow, textvariable=self.labelPrice, font=("arial", 14)).grid(row=1, column=2, sticky=N, padx=6, pady=6)
  73. ######################### dynamic label working :D ######################
  74. self.store_menu = StringVar()
  75. self.store_menu.set("please select a game")
  76. self.store_menu.trace("w", self.select_game)
  77. self.store_menuoption = OptionMenu(self.buywindow, self.store_menu, command=self.update, *gameList).grid(row=1, column=1, sticky=N, padx=6, rowspan=1)
  78. ########################
  79. self.loading = Button(self.buywindow, text="add to cart", command=self.purchasing, state="disabled")#changing test() to test make it so that a button is needed,
  80. self.loading.grid(row=3, column=1)
  81. #############buying process
  82. self.buy = Button(self.buywindow, text="checkout!", command=self.checkout, state="disabled")#changing test() to test make it so that a button is needed,
  83. self.buy.grid(row=3, column=2)
  84.  
  85. def update(self, *args): #price update
  86. for selling_price in gameName:
  87. if selectedgame == selling_price.name:
  88. print("game name:",selectedgame, "game price:",selling_price.price)
  89. post = "$" +str(selling_price.price)
  90. self.labelPrice.set(post)
  91.  
  92. def delete(self, *args): #work on this make it so that they remove an item
  93. global cart, tempcart
  94. print(cart)
  95. removing_from_cart = str(self.removeEntrytext.get())
  96. print("removing_game: ", removing_from_cart)
  97. for x in range(0, len(cart)):
  98. if str(removing_from_cart) == str(cart[int(x)]):
  99. del cart[int(x)] #del that item in the array
  100. #make it so that it can delete relative to the cart list, :C ray
  101. print("2 cart: ", cart)
  102. self.labelNoti.set("removed from cart")
  103. #x += 1
  104. #find a way to update the cart list boi
  105. print('sessionbalance: $', sessionbalance)
  106. else:
  107. x += 1
  108. if not cart:
  109. print("empty") #reset it tho
  110. self.labelNoti.set("doesn't exist")
  111. self.labelCart.set("")#notifications to show what the user have probably should make a remove cart :/
  112. #resetting the text box and the button
  113. #find a way to refersh the tempcart or display cart
  114. for i in range(0, len(cart)): #temp cart is just cart display
  115. tempcart += str(cart[i]) + "\n"
  116. self.labelCart.set(tempcart)#notifications to show what the user have probably should make a remove cart :/
  117. i += 1
  118.  
  119. self.removeEntry.set("######################")
  120. self.removeEntrytext.config(state='disabled')
  121. self.removedbutton.config(state="disabled")
  122. pass
  123.  
  124. def purchasing(self, *args):
  125. global sessionlibrary, selectedgame, sessionbalance, cart, checkout_price, tempcart
  126. tempcart = ""
  127. print(selectedgame)
  128. print("old sesh ", sessionlibrary)
  129. print("selectedgame: ", selectedgame)
  130. if str(selectedgame) not in sessionlibrary and str(selectedgame) not in cart: #if it's not in cart or library
  131. for selling_price in gameName:
  132. if selectedgame == selling_price.name:
  133. print("2 game name:",selectedgame, ", 2 game price: $",selling_price.price)
  134. checkout_price += int(selling_price.price)
  135. print(checkout_price) #adding the prices to the checkout price which will remove from the sessionbalance
  136. cart += str(selectedgame).strip().split(',')#adds in stuff
  137. print("cart ", cart)
  138. print("sessionlibrary: ", sessionlibrary)
  139. self.store_menu.set("please select a game")
  140. self.labelNoti.set("added to cart!")
  141. for i in range(0, len(cart)): #temp cart is just cart display
  142. tempcart += str(cart[i]) + "\n"
  143. self.labelCart.set(tempcart)#notifications to show what the user have probably should make a remove cart :/
  144. i += 1
  145. self.loading.config(state='disabled')
  146. self.buy.config(state='normal')
  147. selectedgame = "" #resetting selected game
  148. self.removeEntrytext.config(state='normal')
  149. self.removedbutton.config(state="normal") #setting it so you can remove from the cart
  150. else:
  151. self.store_menu.set("please select a game")
  152. self.labelNoti.set("you've already bourght \n that game or it's in your\ncart")
  153. self.loading.config(state='disabled')
  154. pass
  155.  
  156. def checkout(self, *args):
  157. global sessionlibrary, cart, selectedgame, sessionbalance, checkout_price
  158. print("cart items: ", cart[0])
  159. #adding the game to the new library
  160. for i in range(0, len(cart)):
  161. sessionlibrary += str(cart[i]).strip().split(',')
  162. print("new sessionlibrary: ", sessionlibrary)
  163. i += 1
  164. cart = []#resstting cart
  165. self.labelCart.set("")
  166. selectedgame = ""
  167. self.buy.config(state='disabled')
  168. self.labelPrice.set("$0")
  169. sessionbalance -= checkout_price
  170. #print(sessionbalance) testting to see if it even gets through
  171. LabelbalanceTitle.set("your current balance is $" +str(sessionbalance))
  172. checkout_price = 0 #ressetting checkout price for the next round :D
  173.  
  174. def select_game(self, *args):
  175. global sessionlibrary, selectedgame
  176. selectedgame = str(self.store_menu.get())
  177. print(selectedgame)
  178. print(sessionlibrary)
  179. self.store_menu.set(selectedgame)
  180. self.loading.config(state='normal')
  181.  
  182. ###############################################################################################################################################################################################
  183.  
  184. class logining():
  185. def __init__(self, *args):
  186. self.loginwindow = Toplevel(root)
  187. self.loginwindow.title("Login")
  188. self.loginwindow.geometry('{}x{}'.format(400, 200))
  189. self.loginwindow.resizable(0,0)
  190. self.loginwindow.grab_set()#made it unclickable
  191. ############################################
  192. labelCom = Label(self.loginwindow, text="login", font=("arial", 24), background="#999", width=10).grid(row=0, column=1, sticky=N, padx=6, pady=6)#login window is 1 frame
  193. labelCom = Label(self.loginwindow, text="username", font=("arial", 18)).grid(row=1, column=0, sticky=N, padx=6, pady=6)
  194. labelCom = Label(self.loginwindow, text="password", font=("arial", 18)).grid(row=2, column=0, sticky=N, padx=6, pady=6)
  195. ############################################
  196. self.usernameEntry = StringVar()
  197. self.usernameEntry.trace("w", lambda name, index, mode, usernameEntry=self.usernameEntry: self.test(self.usernameEntry))
  198. self.usernameEntrytext = Entry(self.loginwindow, textvariable="", state='normal')
  199. self.usernameEntrytext.grid(row=1, column=1, padx=6, pady=6, ipadx=15, ipady=8, rowspan=1, sticky="ew")
  200. ############################################
  201. self.passwordEntry = StringVar()
  202. self.passwordEntry.trace("w", lambda name, index, mode, passwordEntry=self.passwordEntry: self.test(self.passwordEntry))#make sure to add stake holder on the hide password
  203. self.passwordEntrytext = Entry(self.loginwindow, show="*", textvariable="", state='normal')#password thingy
  204. self.passwordEntrytext.grid(row=2, column=1, padx=6, pady=6, ipadx=15, ipady=8, rowspan=1, sticky="ew")
  205. ############################################
  206. #login button
  207. signinButton = Button(self.loginwindow, text="login", command=self.test, state="normal")#changing test() to test make it so that a button is needed,
  208. signinButton.grid(row=3, column=1)
  209. def test(self, *args): #*args is very important
  210. global sessionusername, sessionpassword, sessionlibrary, sessionbalance
  211. entereduser = str(self.usernameEntrytext.get())
  212. enteredpass = str(self.passwordEntrytext.get())
  213. print("####")
  214. print("")
  215. for users in userList:
  216. if entereduser == str(users.username) and enteredpass == str(users.password):
  217. sessionusername = entereduser
  218. sessionpassword = enteredpass
  219. sessionlibrary = users.library
  220. sessionbalance = users.balance
  221. print("current username: " +str(sessionusername), " current password: " +str(sessionpassword), "current library: " +str(sessionlibrary), "current balance:" +str(sessionbalance))
  222. loginButton.config(state="disabled")
  223. logoutButton.config(state="normal")
  224. buyButton.config(state="normal")
  225. LabelbalanceTitle.set("your current balance is $" +str(sessionbalance)) #this one actually worked hmm\
  226. self.loginwindow.destroy()
  227. else:
  228. self.loginwindow.destroy()
  229. print("")
  230. print("####")
  231. ################################################################################################################################################################################################
  232. def logoutfunc(*args):
  233. global sessionusername, sessionpassword, sessionlibrary, sessionbalance
  234. sessionusername = ""
  235. sessionpassword = ""
  236. sessionlibrary = []
  237. LabelbalanceTitle.set("your current balance is $" +str(sessionbalance))
  238. loginButton.config(state="normal")
  239. logoutButton.config(state="disabled") #after loging out it should pretty much reset everything that means clearing everything
  240. print("current username: " +str(sessionusername), " current username: " +str(sessionpassword), "current library: " +str(sessionlibrary), "current balance:" +str(sessionbalance))
  241. ################################################################################################################################################################################################
  242.  
  243. class salesfunc():
  244. global selectedgame, sessionlibrary, sessionbalance, cart
  245. def __init__(self, *args): #REPEATED CODE IS NEEDED for some of the part,
  246. self.saleswindow = Toplevel(root)
  247. self.saleswindow.title("Sales!")
  248. self.saleswindow.geometry('{}x{}'.format(700, 300))
  249. self.saleswindow.resizable(0,0)
  250. self.saleswindow.grab_set()#made it unclickable
  251. #########################
  252. labelCom = Label(self.saleswindow, text="SALES!", font=("arial", 24), background="#999", width=10).grid(row=0, column=1, sticky=N, padx=6, pady=6)
  253. labelgame = Label(self.saleswindow, text="game avaliable", font=("arial", 18)).grid(row=1, column=0, sticky=N, padx=6, pady=6)
  254. ########################
  255.  
  256. ########################
  257. self.labelCartlist = StringVar()
  258. self.labelCartlist.set("games on sale")
  259. self.labelCartContent = Label(self.saleswindow, textvariable=self.labelCartlist, font=("arial", 10)).grid(row=4, column=0, sticky=N, padx=6, pady=6)
  260. #############buying process
  261. self.buy = Button(self.saleswindow, text="buy a game!", command=lambda: Buying(), state="normal")#changing test() to test make it so that a button is needed,
  262. self.buy.grid(row=3, column=2, rowspan=1)
  263.  
  264. ################################################################################################################################################################################################
  265.  
  266. class usersetfunc():
  267. def __init__(self, *args):
  268. self.usersetwindow = Toplevel(root)
  269. self.usersetwindow.title("User Setting")
  270. self.usersetwindow.geometry('{}x{}'.format(400, 300))
  271. self.usersetwindow.resizable(0,0)
  272. self.usersetwindow.grab_set()#made it unclickable
  273.  
  274. ################################################################################################################################################################################################
  275.  
  276. class library():
  277. def __init__(self, *args):
  278. self.librarywindow = Toplevel(root)
  279. self.librarywindow.title("User Setting")
  280. self.librarywindow.geometry('{}x{}'.format(400, 300))
  281. self.librarywindow.resizable(0,0)
  282. self.librarywindow.grab_set()#made it unclickable
  283. #################################################
  284. for i in range(0, len(cart)):
  285. tempcart += str(cart[i]) + "\n"
  286. self.labelCart.set(tempcart)#notifications to show what the user have probably should make a remove cart :/
  287. i += 1
  288.  
  289.  
  290. ################################################################################################################################################################################################
  291.  
  292.  
  293. #interface code it's pretty aesthetic i know
  294. root = Tk()
  295. root.title('Steam Backup Launcher')
  296. root.resizable(0,0)
  297. root.geometry('{}x{}'.format(430, 375))
  298. root.configure(background="black")
  299. mainFrame = Frame(root)
  300. BotFrame = Frame(root)
  301.  
  302. #all these arrays are for filters uwu
  303. gameName = []
  304. gameList = []
  305. userList = []
  306. userName = []
  307. userPass = []
  308. userLib = []
  309. gamePrice = []
  310. cart = []
  311. tempcart = []
  312.  
  313. GTA4 = Game("Grand Theft Auto 4", "3/5", 45, "rockstar", 1) #name, stock, price, publisher
  314. destiny = Game("Destiny", "4/5", 75, "bungie", 1) #name, stock, price, publisher
  315. overwatch = Game("Overwatch", "4/5", 20, "blizzard", 1) #name, stock, price, publisher
  316. red_dead_2 = Game("Red Dead Redemption", "4/5", 90, "rockstar", 1) #name, stock, price, publisher
  317. LOL = Game("League of Legends", "4/5", 10, "riot games", 1) #name, stock, price, publisher
  318.  
  319. jamie = User("t", "t", 0, [GTA4.name, destiny.name, overwatch.name])#game library working! #make a loop that runs througha list
  320. ray = User("test", "test", 244, [GTA4.name, overwatch.name])
  321.  
  322. #globals
  323. sessionusername = ""
  324. sessionpassword = ""
  325. sessionlibrary = []
  326. sessionbalance = 0
  327. checkout_price = 0
  328. selectedgame = ''#needed it for buying class
  329.  
  330. currentlibrary = ['gta','overwatch','destiny']
  331.  
  332. print(GTA4.name + GTA4.rating)
  333. print(jamie.username + " " + str(jamie.library))
  334.  
  335. #title
  336. labelCom = Label(mainFrame, text="steam", font=("arial", 34), background="#999", width=10).grid(row=0, column=1, sticky=N, padx=6, pady=6)
  337.  
  338. #buy pop up box i want to make a list of avaliable game where they can be displayed
  339. buyButton = Button(mainFrame, text="Buy", state='normal', command=lambda: Buying())
  340. buyButton.grid(row=1, column=0, ipadx=10, ipady=5, padx=10)
  341.  
  342. #login button
  343. loginButton = Button(mainFrame, text="Login", command=lambda: logining())
  344. loginButton.grid(row=1, column=2, ipadx=10, ipady=5, padx=10)
  345.  
  346. #logout pop up box i want to make a list of avaliable game where they can be displayed
  347. logoutButton = Button(BotFrame, text="Logout", state='disabled', command=lambda: logoutfunc())
  348. logoutButton.grid(row=3, column=2, ipadx=10, ipady=5, padx=10)
  349.  
  350. #sales pop up box i want to make a list of games of sale
  351. salesButton = Button(BotFrame, text="Sales!", state='normal', command=lambda: salesfunc())
  352. salesButton.grid(row=3, column=0, ipadx=10, ipady=5, padx=10)
  353.  
  354. #settings pop up box i want to make a list of games of sale
  355. usersetButton = Button(BotFrame, text="user setting", state='disabled', command=usersetfunc)
  356. usersetButton.grid(row=2, column=1, ipadx=10, ipady=5, padx=10)
  357.  
  358. #library
  359. libraryButton = Button(mainFrame, text="library", state='normal', command=library, width=10)#run a funciton in login that sets jamie.library to different users
  360. libraryButton.grid(row=2, column=1, padx=20, pady=3)
  361. # i just need to make a button to send it info in since it activates the funciton when a new product is selected (sell button)
  362.  
  363. #balance display
  364. LabelbalanceTitle = StringVar()
  365. LabelbalanceTitle.set("your current balance is $")
  366. LabelbalanceTitleContent = Label(BotFrame, textvariable=LabelbalanceTitle, font=("arial", 9), background="#999", width=30).grid(row=3, column=1, sticky=N, padx=20, pady=3)
  367.  
  368. #main frame
  369. mainFrame.pack(side=TOP, fill=BOTH, expand=TRUE)
  370. BotFrame.pack(side=BOTTOM, fill=BOTH, expand=TRUE)
  371.  
  372. root.mainloop()
  373. #all prints are for testing purposes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement