Advertisement
Guest User

Untitled

a guest
Nov 1st, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.25 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. global selectedgame, sessionlibrary, sessionbalance, cart
  36. price = 0
  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. self.labelCart = StringVar()
  53. self.labelCart.set("")
  54. self.labelCartContent = Label(self.buywindow, textvariable=self.labelCart, font=("arial", 10)).grid(row=5, column=0, sticky=N, padx=6, pady=6)
  55. ########################
  56. self.labelNoti = StringVar()
  57. self.labelNoti.set("")
  58. self.labelNotiContent = Label(self.buywindow, textvariable=self.labelNoti, font=("arial", 8)).grid(row=3, column=0, sticky=N, padx=6, pady=6)
  59. ########################
  60. self.labelPrice = StringVar()
  61. self.labelPrice.set("$0")
  62. self.labelPriceContent = Label(self.buywindow, textvariable=self.labelPrice, font=("arial", 14)).grid(row=1, column=2, sticky=N, padx=6, pady=6)
  63. ######################### dynamic label working :D ######################
  64. ########################
  65. self.store_menu = StringVar()
  66. self.store_menu.set("please select a game")
  67. self.store_menu.trace("w", self.select_game)
  68. self.store_menuoption = OptionMenu(self.buywindow, self.store_menu, *gameList).grid(row=1, column=1, sticky=N, padx=6, rowspan=1)
  69. ########################
  70. 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,
  71. self.loading.grid(row=3, column=1)
  72. #############buying process
  73. self.buy = Button(self.buywindow, text="checkout!", command=self.checkout, state="disabled")#changing test() to test make it so that a button is needed,
  74. self.buy.grid(row=3, column=2)
  75.  
  76. def purchasing(self, *args):
  77. global sessionlibrary, selectedgame, sessionbalance, cart
  78. tempcart = ""
  79. print("old sesh ", sessionlibrary)
  80. print("selectedgame: ", selectedgame)
  81. if str(selectedgame) not in sessionlibrary and str(selectedgame) not in cart: #if it's not in cart or library
  82. cart += str(selectedgame).strip().split(',')#adds in stuff
  83. print("cart ", cart)
  84. print("sessionlibrary: ", sessionlibrary)
  85. self.store_menu.set("please select a game")
  86. self.labelNoti.set("added to cart!")
  87. selectedgame = "" #resetting selected game
  88. ####################################################################
  89.  
  90. for selling_price in gameName: #find the game from the same class and change the label to it @ray
  91. if selectedgame == selling_price.price:
  92. print("hi", selectedgame, selling_price.price)
  93.  
  94. ####################################################################
  95. for i in range(0, len(cart)):
  96. tempcart += str(cart[i]) + "\n"
  97. self.labelCart.set(tempcart)#notifications to show what the user have probably should make a remove cart :/
  98. i += 1
  99. self.loading.config(state='disabled')
  100. self.buy.config(state='normal')
  101. elif str(selectedgame) in sessionlibrary and str(selectedgame) in cart:
  102. self.labelNoti.set("you've already bought it")
  103. self.store_menu.set("please select a game")
  104. self.loading.config(state='disabled')
  105. else:
  106. self.store_menu.set("please select a game")
  107. self.labelNoti.set("you've already bourght \n that game or it's in your\ncart")
  108. self.loading.config(state='disabled')
  109. pass
  110.  
  111. def checkout(self, *args):
  112. global sessionlibrary, cart, selectedgame
  113. print("cart items: ", cart[0])
  114. if str(selectedgame) not in sessionlibrary:
  115. for i in range(0, len(cart)):
  116. sessionlibrary += str(cart[i]).strip().split(',')
  117. print("new sessionlibrary: ", sessionlibrary)
  118. i += 1
  119. cart = []#resstting cart
  120. self.labelCart.set("")
  121. selectedgame = ""
  122. self.buy.config(state='disabled')
  123. else:
  124. print("goof'd")
  125.  
  126. def select_game(self, *args):
  127. global sessionlibrary, selectedgame
  128. selectedgame = str(self.store_menu.get())
  129. print(selectedgame)
  130. print(sessionlibrary)
  131. self.store_menu.set(selectedgame)
  132. self.loading.config(state='normal')
  133.  
  134.  
  135.  
  136. ################################################################################################################################################################################################
  137.  
  138. class logining():
  139. def __init__(self, *args):
  140. self.loginwindow = Toplevel(root)
  141. self.loginwindow.title("Login")
  142. self.loginwindow.geometry('{}x{}'.format(400, 200))
  143. self.loginwindow.resizable(0,0)
  144. self.loginwindow.grab_set()#made it unclickable
  145. ############################################
  146. 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
  147. labelCom = Label(self.loginwindow, text="username", font=("arial", 18)).grid(row=1, column=0, sticky=N, padx=6, pady=6)
  148. labelCom = Label(self.loginwindow, text="password", font=("arial", 18)).grid(row=2, column=0, sticky=N, padx=6, pady=6)
  149. ############################################
  150. self.usernameEntry = StringVar()
  151. self.usernameEntry.trace("w", lambda name, index, mode, usernameEntry=self.usernameEntry: self.test(self.usernameEntry))
  152. self.usernameEntrytext = Entry(self.loginwindow, textvariable="", state='normal')
  153. self.usernameEntrytext.grid(row=1, column=1, padx=6, pady=6, ipadx=15, ipady=8, rowspan=1, sticky="ew")
  154. ############################################
  155. self.passwordEntry = StringVar()
  156. 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
  157. self.passwordEntrytext = Entry(self.loginwindow, show="*", textvariable="", state='normal')#password thingy
  158. self.passwordEntrytext.grid(row=2, column=1, padx=6, pady=6, ipadx=15, ipady=8, rowspan=1, sticky="ew")
  159. ############################################
  160. #login button
  161. signinButton = Button(self.loginwindow, text="login", command=self.test, state="normal")#changing test() to test make it so that a button is needed,
  162. signinButton.grid(row=3, column=1)
  163.  
  164. def test(self, *args): #*args is very important
  165. global sessionusername, sessionpassword, sessionlibrary, sessionbalance
  166. entereduser = str(self.usernameEntrytext.get())
  167. enteredpass = str(self.passwordEntrytext.get())
  168. print("####")
  169. print("")
  170. for users in userList:
  171. if entereduser == str(users.username) and enteredpass == str(users.password):
  172. sessionusername = entereduser
  173. sessionpassword = enteredpass
  174. sessionlibrary = users.library
  175. sessionbalance = users.balance
  176. print("current username: " +str(sessionusername), " current password: " +str(sessionpassword), "current library: " +str(sessionlibrary), "current balance:" +str(sessionbalance))
  177. #print("good")#signin working
  178. loginButton.config(state="disabled")
  179. logoutButton.config(state="normal")
  180. buyButton.config(state="normal")
  181. #library_menu.configure(*sessionlibrary)#sorta did it finally getting somewhere
  182. #del gameList[:]
  183. print(gameList)
  184. #for games in currentlibrary:
  185.  
  186. LabelbalanceTitle.set("your current balance is $" +str(sessionbalance)) #this one actually worked hmm\
  187. self.loginwindow.destroy()
  188. else:
  189. self.loginwindow.destroy()
  190. print("")
  191. print("####")
  192.  
  193. ################################################################################################################################################################################################
  194.  
  195. def logoutfunc(*args):
  196. global sessionusername, sessionpassword, sessionlibrary, sessionbalance
  197. sessionusername = ""
  198. sessionpassword = ""
  199. sessionlibrary = []
  200. LabelbalanceTitle.set("your current balance is $" +str(sessionbalance))
  201. loginButton.config(state="normal")
  202. logoutButton.config(state="disabled") #after loging out it should pretty much reset everything that means clearing everything
  203. print("current username: " +str(sessionusername), " current username: " +str(sessionpassword), "current library: " +str(sessionlibrary), "current balance:" +str(sessionbalance))
  204.  
  205. ################################################################################################################################################################################################
  206.  
  207. class salesfunc():
  208. def __init__(self, *args):
  209. self.saleswindow = Toplevel(root)
  210. self.saleswindow.title("Sales!")
  211. self.saleswindow.geometry('{}x{}'.format(400, 300))
  212. self.saleswindow.resizable(0,0)
  213. self.saleswindow.grab_set()#made it unclickable
  214.  
  215. ################################################################################################################################################################################################
  216.  
  217. class usersetfunc():
  218. def __init__(self, *args):
  219. self.usersetwindow = Toplevel(root)
  220. self.usersetwindow.title("User Setting")
  221. self.usersetwindow.geometry('{}x{}'.format(400, 300))
  222. self.usersetwindow.resizable(0,0)
  223. self.usersetwindow.grab_set()#made it unclickable
  224.  
  225. ################################################################################################################################################################################################
  226.  
  227. def library(*args):
  228. print("something")
  229. pass
  230.  
  231. ################################################################################################################################################################################################
  232.  
  233.  
  234. #interface code it's pretty aesthetic i know
  235. root = Tk()
  236. root.title('Steam Backup Launcher')
  237. root.resizable(0,0)
  238. root.geometry('{}x{}'.format(430, 375))
  239. root.configure(background="black")
  240. mainFrame = Frame(root)
  241. BotFrame = Frame(root)
  242.  
  243. #all these arrays are for filters uwu
  244. gameName = []
  245. gameList = []
  246. userList = []
  247. userName = []
  248. userPass = []
  249. userLib = []
  250. gamePrice = []
  251. cart = []
  252.  
  253.  
  254. GTA4 = Game("Grand Theft Auto 4", "3/5", 45, "rockstar", 1) #name, stock, price, publisher
  255. destiny = Game("Destiny", "4/5", 75, "bungie", 1) #name, stock, price, publisher
  256. overwatch = Game("Overwatch", "4/5", 20, "blizzard", 1) #name, stock, price, publisher
  257. red_dead_2 = Game("Red Dead Redemption", "4/5", 90, "rockstar", 1) #name, stock, price, publisher
  258. LOL = Game("League of Legends", "4/5", 10, "riot games", 1) #name, stock, price, publisher
  259.  
  260. jamie = User("t", "t", 0, [GTA4.name, destiny.name, overwatch.name])#game library working! #make a loop that runs througha list
  261. ray = User("test", "test", 244, [GTA4.name, overwatch.name])
  262.  
  263. #globals
  264. sessionusername = ""
  265. sessionpassword = ""
  266. sessionlibrary = []
  267. sessionbalance = 0
  268. selectedgame = ''#needed it for buying class
  269.  
  270. currentlibrary = ['gta','overwatch','destiny']
  271.  
  272. print(GTA4.name + GTA4.rating)
  273. print(jamie.username + " " + str(jamie.library))
  274.  
  275. #title
  276. labelCom = Label(mainFrame, text="steam", font=("arial", 34), background="#999", width=10).grid(row=0, column=1, sticky=N, padx=6, pady=6)
  277.  
  278. #buy pop up box i want to make a list of avaliable game where they can be displayed
  279. buyButton = Button(mainFrame, text="Buy", state='normal', command=lambda: Buying())
  280. buyButton.grid(row=1, column=0, ipadx=10, ipady=5, padx=10)
  281.  
  282. #login button
  283. loginButton = Button(mainFrame, text="Login", command=lambda: logining())
  284. loginButton.grid(row=1, column=2, ipadx=10, ipady=5, padx=10)
  285.  
  286. #logout pop up box i want to make a list of avaliable game where they can be displayed
  287. logoutButton = Button(BotFrame, text="Logout", state='disabled', command=lambda: logoutfunc())
  288. logoutButton.grid(row=3, column=2, ipadx=10, ipady=5, padx=10)
  289.  
  290. #sales pop up box i want to make a list of games of sale
  291. salesButton = Button(BotFrame, text="Sales!", state='normal', command=lambda: salesfunc())
  292. salesButton.grid(row=3, column=0, ipadx=10, ipady=5, padx=10)
  293.  
  294. #settings pop up box i want to make a list of games of sale
  295. usersetButton = Button(BotFrame, text="user setting", state='disabled', command=usersetfunc)
  296. usersetButton.grid(row=2, column=1, ipadx=10, ipady=5, padx=10)
  297.  
  298. #library
  299. library_menu = StringVar()
  300. library_menu.set("this is your library")
  301. #library_menu("w", library)
  302. library_menu_Content = OptionMenu(mainFrame, library_menu, *currentlibrary).grid(row=2, column=1, sticky=N, padx=6) #run a funciton in login that sets jamie.library to different users
  303. # 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)
  304.  
  305. #balance display
  306. LabelbalanceTitle = StringVar()
  307. LabelbalanceTitle.set("your current balance is $")
  308. LabelbalanceTitleContent = Label(BotFrame, textvariable=LabelbalanceTitle, font=("arial", 9), background="#999", width=30).grid(row=3, column=1, sticky=N, padx=20, pady=3)
  309.  
  310. #main frame
  311. mainFrame.pack(side=TOP, fill=BOTH, expand=TRUE)
  312. BotFrame.pack(side=BOTTOM, fill=BOTH, expand=TRUE)
  313.  
  314. root.mainloop()
  315. #all prints are for testing purposes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement