Advertisement
Guest User

Untitled

a guest
Oct 30th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.05 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. class Game:
  9. def __init__(self, name, rating, price, publisher, sale):
  10. self.name = name
  11. self.rating = rating
  12. self.price = price
  13. self.publisher = publisher
  14. self.sale = sale #will be used a mutliplier e.g. 0.6 x price, 1 x price (default)
  15. gameList.append(self)
  16.  
  17. class User:
  18. def __init__(self, username, password, balance, library):
  19. self.username = username
  20. self.password = password
  21. self.balance = balance
  22. self.library = library #this will be an array which will be added via, gta.name etc
  23. userList.append(self)
  24.  
  25.  
  26. class Buying():
  27. def __init__(self, *args): #REPEATED CODE IS NEEDED for some of the part,
  28. self.buywindow = Toplevel(root)
  29. self.buywindow.title("buy a game")
  30. self.buywindow.geometry('{}x{}'.format(500, 530))
  31. self.buywindow.resizable(0,0)
  32. self.buywindow.grab_set()#made it unclickable
  33. #########################
  34. labelCom = Label(self.buywindow, text="Purchase", font=("arial", 24), background="#999", width=10).grid(row=0, column=1, sticky=N, padx=6, pady=6)
  35. labelgame = Label(self.buywindow, text="game avaliable", font=("arial", 18)).grid(row=1, column=0, sticky=N, padx=6, pady=6)
  36. labelCopies = Label(self.buywindow, text="how many copies", font=("arial", 18)).grid(row=2, column=0, sticky=N, padx=6, pady=6)
  37. ########################
  38. self.labelNoti = StringVar()
  39. self.labelNoti.set("asdf")
  40. self.labelNotiContent = Label(self.buywindow, textvariable=self.labelNoti, font=("arial", 8)).grid(row=3, column=0, sticky=N, padx=6, pady=6)
  41. ######################### dynamic label working :D ######################
  42. self.copiesEntry = StringVar()
  43. self.copiesEntry.trace("w", lambda name, index, mode, copiesEntry=self.copiesEntry: self.check_value(self.copiesEntry))
  44. self.copiesEntrytext = Entry(self.buywindow, textvariable=self.copiesEntry, state='normal')
  45. self.copiesEntrytext.grid(row=2, column=1, padx=6, pady=6, ipadx=15, ipady=8, rowspan=1, sticky="ew")
  46. ########################
  47. self.store_menu = StringVar()
  48. self.store_menu.set("this is your library")
  49. #self.store_menu("w", library)
  50. self.store_menu = OptionMenu(self.buywindow, self.testing, *gameList).grid(row=1, column=1, sticky=N, padx=6)
  51.  
  52. def check_value(self, *args):
  53. inputedcopies = int(self.copiesEntrytext.get())
  54. print(inputedcopies)
  55. if inputedcopies <= 10:
  56. self.labelNoti.set("purchased")
  57. else:
  58. self.copiesEntry.set("")
  59. self.labelNoti.set("too many copies")
  60. #print("worked")
  61. def testing(self, *args):
  62. print("working")
  63.  
  64. ################################################################################################################################################################################################
  65. class logining():
  66. def __init__(self, *args):
  67. self.loginwindow = Toplevel(root)
  68. self.loginwindow.title("Login")
  69. self.loginwindow.geometry('{}x{}'.format(400, 200))
  70. self.loginwindow.resizable(0,0)
  71. self.loginwindow.grab_set()#made it unclickable
  72. ############################################
  73. 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
  74. labelCom = Label(self.loginwindow, text="username", font=("arial", 18)).grid(row=1, column=0, sticky=N, padx=6, pady=6)
  75. labelCom = Label(self.loginwindow, text="password", font=("arial", 18)).grid(row=2, column=0, sticky=N, padx=6, pady=6)
  76. ############################################
  77. self.usernameEntry = StringVar()
  78. self.usernameEntry.trace("w", lambda name, index, mode, usernameEntry=self.usernameEntry: self.test(self.usernameEntry))
  79. self.usernameEntrytext = Entry(self.loginwindow, textvariable="", state='normal')
  80. self.usernameEntrytext.grid(row=1, column=1, padx=6, pady=6, ipadx=15, ipady=8, rowspan=1, sticky="ew")
  81. ############################################
  82. self.passwordEntry = StringVar()
  83. 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
  84. self.passwordEntrytext = Entry(self.loginwindow, show="*", textvariable="", state='normal')#password thingy
  85. self.passwordEntrytext.grid(row=2, column=1, padx=6, pady=6, ipadx=15, ipady=8, rowspan=1, sticky="ew")
  86. ############################################
  87. #login button
  88. signinButton = Button(self.loginwindow, text="login", command=self.test, state="normal")#changing test() to test make it so that a button is needed,
  89. signinButton.grid(row=3, column=1)
  90.  
  91. def test(self, *args): #*args is very important
  92. global sessionusername, sessionpassword, sessionlibrary, sessionbalance
  93. entereduser = str(self.usernameEntrytext.get())
  94. enteredpass = str(self.passwordEntrytext.get())
  95. print("####")
  96. print("")
  97. #print(self.usernameEntrytext.get(), self.passwordEntrytext.get())
  98. for users in userList:
  99. if entereduser == str(users.username) and enteredpass == str(users.password):
  100. sessionusername = entereduser
  101. sessionpassword = enteredpass
  102. sessionlibrary = users.library
  103. sessionbalance = users.balance
  104. print("current username: " +str(sessionusername), " current password: " +str(sessionpassword), "current library: " +str(sessionlibrary), "current balance:" +str(sessionbalance))
  105. #print("good")#signin working
  106. loginButton.config(state="disabled")
  107. logoutButton.config(state="normal")
  108. buyButton.config(state="normal")
  109. LabelbalanceTitle.set("your current balance is $" +str(sessionbalance)) #this one actually worked hmm
  110. library_menu.set(sessionlibrary)
  111. self.loginwindow.destroy()
  112. else:
  113. self.loginwindow.destroy()
  114. #print(sessionusername, sessionpassword)
  115. print("")
  116. print("####")
  117. #asdf = usernameEntrytext.get()
  118. #print(asdf)
  119. #if username1 == username and password1 == password:
  120. # print("it worked")
  121. #else:
  122. # print("failed")
  123. #
  124. ################################################################################################################################################################################################
  125. def logoutfunc(*args):
  126. global sessionusername, sessionpassword, sessionlibrary, sessionbalance
  127. sessionusername = ""
  128. sessionpassword = ""
  129. sessionlibrary = []
  130. sessionbalance = ""
  131. loginButton.config(state="normal")
  132. logoutButton.config(state="disabled") #after loging out it should pretty much reset everything that means clearing everything
  133. print("current username: " +str(sessionusername), " current username: " +str(sessionpassword), "current library: " +str(sessionlibrary), "current balance:" +str(sessionbalance))
  134.  
  135. def salesfunc(*args):
  136. saleswindow = Toplevel(root)
  137. saleswindow.title("Sales!")
  138. saleswindow.geometry('{}x{}'.format(400, 300))
  139. saleswindow.resizable(0,0)
  140. saleswindow.grab_set()#made it unclickable
  141.  
  142. def usersetfunc(*args):
  143. usersetwindow = Toplevel(root)
  144. usersetwindow.title("User Setting")
  145. usersetwindow.geometry('{}x{}'.format(400, 300))
  146. usersetwindow.resizable(0,0)
  147. usersetwindow.grab_set()#made it unclickable
  148.  
  149. def library(*args):
  150. library_menu.set(sessionlibrary)
  151.  
  152. #interface code it's pretty aesthetic i know
  153. root = Tk()
  154. root.title('Steam Backup Launcher')
  155. root.resizable(0,0)
  156. root.geometry('{}x{}'.format(430, 375))
  157. root.configure(background="black")
  158. mainFrame = Frame(root)
  159. BotFrame = Frame(root)
  160.  
  161. #all these arrays are for filters uwu
  162. gameNames = []
  163. gameList = []
  164. userList = []
  165. userName = []
  166. userPass = []
  167.  
  168.  
  169. GTA4 = Game("grand theft auto 4", "3/5", 45, "rockstar", 1) #name, stock, price, publisher
  170. destiny = Game("destiny", "4/5", 45, "bungie", 1) #name, stock, price, publisher
  171. overwatch = Game("overwatch", "4/5", 60, "blizzard", 1) #name, stock, price, publisher
  172. jamie = User("joji", "2low4ahoe", 0, [GTA4.name, destiny.name, overwatch.name])#game library working! #make a loop that runs througha list
  173. ray = User("test", "test", 244, [GTA4.name, overwatch.name])
  174. #globals
  175. sessionusername = ""
  176. sessionpassword = ""
  177. sessionlibrary = [""]
  178. sessionbalance = 0
  179.  
  180. currentlibrary = ['gta','overwatch','destiny']
  181.  
  182. print(GTA4.name + GTA4.rating)
  183. print(jamie.username + " " + str(jamie.library))
  184.  
  185. #title
  186. labelCom = Label(mainFrame, text="steam", font=("arial", 34), background="#999", width=10).grid(row=0, column=1, sticky=N, padx=6, pady=6)
  187.  
  188. #buy pop up box i want to make a list of avaliable game where they can be displayed
  189. buyButton = Button(mainFrame, text="Buy", state='normal', command=lambda: Buying())
  190. buyButton.grid(row=1, column=0, ipadx=10, ipady=5, padx=10)
  191.  
  192. #login button
  193. loginButton = Button(mainFrame, text="Login", command=lambda: logining())
  194. loginButton.grid(row=1, column=2, ipadx=10, ipady=5, padx=10)
  195.  
  196. #logout pop up box i want to make a list of avaliable game where they can be displayed
  197. logoutButton = Button(BotFrame, text="Logout", state='disabled', command=lambda: logoutfunc())
  198. logoutButton.grid(row=3, column=2, ipadx=10, ipady=5, padx=10)
  199.  
  200. #sales pop up box i want to make a list of games of sale
  201. salesButton = Button(BotFrame, text="Sales!", state='disabled', command=salesfunc)
  202. salesButton.grid(row=3, column=0, ipadx=10, ipady=5, padx=10)
  203.  
  204. #settings pop up box i want to make a list of games of sale
  205. usersetButton = Button(BotFrame, text="user setting", state='disabled', command=usersetfunc)
  206. usersetButton.grid(row=2, column=1, ipadx=10, ipady=5, padx=10)
  207.  
  208. #library
  209. library_menu = StringVar()
  210. library_menu.set("this is your library")
  211. #library_menu("w", library)
  212. library_menu_Content = OptionMenu(mainFrame, logoutfunc, *currentlibrary).grid(row=2, column=1, sticky=N, padx=6) #run a funciton in login that sets jamie.library to different users
  213. # 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)
  214.  
  215. #balance display
  216. LabelbalanceTitle = StringVar()
  217. LabelbalanceTitle.set("your current balance is $")
  218. LabelbalanceTitleContent = Label(BotFrame, textvariable=LabelbalanceTitle, font=("arial", 9), background="#999", width=30).grid(row=3, column=1, sticky=N, padx=20, pady=3)
  219.  
  220. #main frame
  221. mainFrame.pack(side=TOP, fill=BOTH, expand=TRUE)
  222. BotFrame.pack(side=BOTTOM, fill=BOTH, expand=TRUE)
  223.  
  224. root.mainloop()
  225. #all prints are for testing purposes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement