Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.13 KB | None | 0 0
  1. import tkinter as tk
  2. from os import path
  3. from datetime import datetime
  4. from webbrowser import open as wOpen
  5. from pathlib import Path
  6. from PCBuilder import buildPC
  7. import os
  8.  
  9. def error():
  10.     wOpen("https://github.com/NasifQadri/PCBuilder/issues/new", new=2)
  11.      
  12.  
  13. # GET CURRENT WORKING DIRECTORY
  14. cwd = str(Path(__file__).parent.absolute())
  15. cwd = cwd.replace("\\","/")
  16. resources = (str(cwd) + "/Resources/")
  17. icon = resources + "icon.ico"
  18.  
  19. root= tk.Tk()
  20. root.title("PC Builder")
  21.  
  22. root.iconbitmap(icon)
  23. screen = tk.Canvas(root, width = 400, height = 300)
  24. screen.pack()
  25.  
  26.  
  27.  
  28. label1 = tk.Label(root, text="PC Builder", font=("helvetica",14))
  29. screen.create_window(200, 25, window=label1)
  30.  
  31. label2 = tk.Label(root, text="Enter your Budget in US Dollars:", font=("helvetica", 10))
  32. screen.create_window(200, 100, window=label2)
  33.  
  34. budgetEntry = tk.Entry (root)
  35. screen.create_window(200, 140, window=budgetEntry)
  36.  
  37.  
  38. time = lambda format : datetime.now().strftime(format)
  39.  
  40.  
  41. # CREATES WINDOW WITH THE COMPLETED BUILD
  42. def getOutput():
  43.     usage.destroy()
  44.     build = (buildPC(budget,cpu.get(),use.get()))
  45.     if build.startswith("ERROR:"):
  46.         if build.endswith("dollars"):
  47.             pass
  48.         else:
  49.             error()
  50.         output = tk.Tk()
  51.         output.title("Completed Build")
  52.         output.iconbitmap(icon)
  53.         outputWindow = tk.Canvas(output, width = 600, height = 300,bg = "red")
  54.         outputWindow.pack()
  55.         outputLabel = tk.Label(output, text = build, font=("helvetica",15),fg = "white", bg = "red")
  56.         outputWindow.create_window(300,100, window=outputLabel)
  57.     else:
  58.         output = tk.Tk()
  59.         output.title("Completed Build")
  60.         output.iconbitmap(icon)
  61.         outputWindow = tk.Canvas(output, width = 600, height = 300)
  62.         outputWindow.pack()
  63.         outputLabel = tk.Label(output, text = build, font=("consolas",10))
  64.         outputWindow.create_window(300,100, window=outputLabel)
  65.         if build.startswith("You"):
  66.             pass
  67.         else:
  68.             fileName = "/" + time("Build - %d/%m/%Y@%H-%M-%S") + ".txt"
  69.             fileDir = str(cwd) + fileName
  70.  
  71.             print(fileDir)
  72.             with open(fileDir,"w+") as f:
  73.                 f.write(build)
  74.                 f.close()
  75.  
  76. # GET USAGE(WORK OR GAMING)      
  77. def getUsage():
  78.     global use
  79.     global usage
  80.     processor.destroy()
  81.     usage = tk.Tk()
  82.     usage.title("Select Usage")
  83.     usage.iconbitmap(icon)
  84.     usageSelect = tk.Canvas(usage, width = 300, height = 25)
  85.     usageSelect.pack()
  86.     usageLabel = tk.Label(usage, text = "What is your main usage?", font=("helvetica",13))
  87.  
  88.     usageSelect.create_window(150, 15, window=usageLabel)
  89.     use = tk.StringVar(usage)
  90.     tk.Radiobutton(usage,command = getOutput, text = "Work", variable = use,value = "Work", indicator = 0,background = "grey33").pack(fill = "x", ipady = 20)
  91.     tk.Radiobutton(usage,command = getOutput, text = "Gaming", variable = use,value = "Gaming", indicator = 0,background = "grey66").pack(fill = "x", ipady = 20)
  92.  
  93.  
  94. # GET CPU (AMD OR INTEL)
  95. def getCPU():
  96.     global cpu
  97.     global processor
  98.     processor = tk.Tk()
  99.     processor.title("Processor Selection")
  100.     processor.iconbitmap(icon)
  101.     processorSelect = tk.Canvas(processor, width = 300, height = 25)
  102.     processorSelect.pack()
  103.     cpuLabel = tk.Label(processor, text = "Select your preferred processor brand", font=("helvetica",13))
  104.     processorSelect.create_window(150, 15, window=cpuLabel)
  105.     cpu = tk.StringVar(processor)
  106.     tk.Radiobutton(processor, text = "Intel", variable = cpu,value = "Intel",command = getUsage, indicator = 0,background = "#0071c5").pack(fill = "x", ipady = 20)
  107.     tk.Radiobutton(processor, text = "AMD", variable = cpu,value = "AMD",command = getUsage, indicator = 0,background = "#ca0505").pack(fill = "x", ipady = 20)
  108.  
  109. # GET BUDGET FROM ENTRY
  110. def getBudget():
  111.     global budget
  112.     budget = (budgetEntry.get())
  113.     getCPU()
  114.  
  115. button1 = tk.Button(text="Confirm budget", command=getBudget, bg="brown", fg="white", relief = "flat", font=("helvetica", 9, "bold"))
  116. screen.create_window(200, 180, window=button1)
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement