Advertisement
Guest User

Untitled

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