Advertisement
TrashRat

OneStop - Tabletop Shop Inventory Manegment

May 11th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.31 KB | None | 0 0
  1. !-----"OneStopShop.py"-----!
  2. import sys
  3. import xlsxwriter
  4. import pyexcel
  5. import random
  6. import openpyxl
  7. from tkinter import *
  8. from tkinter import filedialog, messagebox
  9. from openpyxl.styles import Alignment
  10. import tkinter.ttk as ttk
  11. py3 = 1
  12.  
  13. def OnClosing():
  14.     if messagebox.askokcancel("WARNING", "Are you sure you want to quit?\nUnexported data will be lost."):
  15.         root.destroy()
  16. def vp_start_gui():
  17.     '''Starting point when module is the main routine.'''
  18.     global val, w, root
  19.     root = Tk()
  20.     root.iconbitmap("icon.ico")
  21.     top = OneStop (root)
  22.     root.protocol("WM_DELETE_WINDOW", OnClosing)
  23.     root.mainloop()
  24.  
  25. w = None
  26. def create_OneStop(root, *args, **kwargs):
  27.     '''Starting point when module is imported by another program.'''
  28.     global w, w_win, rt
  29.     rt = root
  30.     w = Toplevel (root)
  31.     top = OneStop (w)
  32.  
  33.     return (w, top)
  34.  
  35. def destroy_OneStop():
  36.     global w
  37.     w.destroy()
  38.     w = None
  39.  
  40.  
  41. class OneStop:
  42.     def __init__(self, top=None):
  43.         '''This class configures and populates the toplevel window.
  44.           top is the toplevel containing window.'''
  45.         _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
  46.         _fgcolor = '#000000'  # X11 color: 'black'
  47.         _compcolor = '#d9d9d9' # X11 color: 'gray85'
  48.         _ana1color = '#d9d9d9' # X11 color: 'gray85'
  49.         _ana2color = '#d9d9d9' # X11 color: 'gray85'
  50.         self.style = ttk.Style()
  51.         if sys.platform == "win32":
  52.             self.style.theme_use('winnative')
  53.         self.style.configure('.',background=_bgcolor)
  54.         self.style.configure('.',foreground=_fgcolor)
  55.         self.style.map('.',background=
  56.             [('selected', _compcolor), ('active',_ana2color)])
  57.  
  58.         top.geometry("534x309+637+323")
  59.         top.title("OneStop")
  60.         top.configure(background="#d9d9d9")
  61.         top.configure(highlightbackground="#d9d9d9")
  62.         top.configure(highlightcolor="black")
  63.         top.bind("<Delete>", self.DelEntry)
  64.         top.bind("<Insert>", self.SaveEntry)
  65.         #top.bind("<End>", self.AddEntry)
  66.        
  67.         self.ItemList = []
  68.  
  69.         def onSelect(event):
  70.            
  71.             self.Description.delete('1.0',END)
  72.             self.BasePrice.delete('0',END)
  73.             self.HighPrice.delete('0',END)
  74.             self.LowPrice.delete('0',END)
  75.             self.RandPrice.delete('0',END)
  76.             current = self.ShopInventory.get(self.ShopInventory.curselection())
  77.             try:
  78.                 result = next(sublist for sublist in self.ItemList if sublist[0] == current) #the sublist pulled out of main self.ItemList
  79.             except StopIteration as e:
  80.                 self.ItemList = self.ItemList[0]
  81.                 result = next(sublist for sublist in self.ItemList if sublist[0] == current)
  82.    
  83.                
  84.            
  85.             if self.Description.get('1.0', END) == result[1]:
  86.                 pass
  87.             else:
  88.                 self.Description.insert(END,result[1])
  89.                 self.BasePrice.insert(END,result[2])
  90.                 self.HighPrice.insert(END,result[3])
  91.                 self.LowPrice.insert(END,result[4])
  92.                 self.RandPrice.insert(END,result[5])
  93.                
  94.                
  95.         self.ShopInventory = ScrolledListBox(top)
  96.         self.ShopInventory.place(relx=0.0, rely=0.02, relheight=0.96  
  97.                 , relwidth=0.4)
  98.         self.ShopInventory.configure(background="white")
  99.         self.ShopInventory.configure(disabledforeground="#a3a3a3")
  100.         self.ShopInventory.configure(font="TkFixedFont")
  101.         self.ShopInventory.configure(foreground="black")
  102.         self.ShopInventory.configure(highlightbackground="#d9d9d9")
  103.         self.ShopInventory.configure(highlightcolor="#d9d9d9")
  104.         self.ShopInventory.configure(selectbackground="#c4c4c4")
  105.         self.ShopInventory.configure(selectforeground="black")
  106.         self.ShopInventory.configure(width=10)
  107.         self.ShopInventory.bind("<<ListboxSelect>>", onSelect)
  108.        
  109.         self.ImportButton = Button(top, command=self.ImportFile)
  110.         self.ImportButton.place(relx=0.41, rely=0.91, height=24, width=87)
  111.         self.ImportButton.configure(activebackground="#d9d9d9")
  112.         self.ImportButton.configure(activeforeground="#000000")
  113.         self.ImportButton.configure(background="#d9d9d9")
  114.         self.ImportButton.configure(disabledforeground="#a3a3a3")
  115.         self.ImportButton.configure(foreground="#000000")
  116.         self.ImportButton.configure(highlightbackground="#d9d9d9")
  117.         self.ImportButton.configure(highlightcolor="black")
  118.         self.ImportButton.configure(pady="0")
  119.         self.ImportButton.configure(text='''Import''')
  120.  
  121.         self.ExportButton = Button(top, command = self.ExportFile)
  122.         self.ExportButton.place(relx=0.82, rely=0.91, height=24, width=87)
  123.         self.ExportButton.configure(activebackground="#d9d9d9")
  124.         self.ExportButton.configure(activeforeground="#000000")
  125.         self.ExportButton.configure(background="#d9d9d9")
  126.         self.ExportButton.configure(disabledforeground="#a3a3a3")
  127.         self.ExportButton.configure(foreground="#000000")
  128.         self.ExportButton.configure(highlightbackground="#d9d9d9")
  129.         self.ExportButton.configure(highlightcolor="black")
  130.         self.ExportButton.configure(pady="0")
  131.         self.ExportButton.configure(text='''Export''')
  132.  
  133.         self.SaveEntry = Button(top, command = self.SaveEntry)
  134.         self.SaveEntry.place(relx=0.62, rely=0.78, height=24, width=87)
  135.         self.SaveEntry.configure(activebackground="#d9d9d9")
  136.         self.SaveEntry.configure(activeforeground="#000000")
  137.         self.SaveEntry.configure(background="#d9d9d9")
  138.         self.SaveEntry.configure(disabledforeground="#a3a3a3")
  139.         self.SaveEntry.configure(foreground="#000000")
  140.         self.SaveEntry.configure(highlightbackground="#d9d9d9")
  141.         self.SaveEntry.configure(highlightcolor="black")
  142.         self.SaveEntry.configure(pady="0")
  143.         self.SaveEntry.configure(text='''Save Entry''')
  144.  
  145.         self.BaseN = Label(top)
  146.         self.BaseN.place(relx=0.41, rely=0.58, height=31, width=64)
  147.         self.BaseN.configure(activebackground="#f9f9f9")
  148.         self.BaseN.configure(activeforeground="black")
  149.         self.BaseN.configure(background="#d9d9d9")
  150.         self.BaseN.configure(disabledforeground="#a3a3a3")
  151.         self.BaseN.configure(foreground="#000000")
  152.         self.BaseN.configure(highlightbackground="#d9d9d9")
  153.         self.BaseN.configure(highlightcolor="black")
  154.         self.BaseN.configure(text='''Base''')
  155.         self.BaseN.configure(width=64)
  156.  
  157.         self.HighN = Label(top)
  158.         self.HighN.place(relx=0.56, rely=0.58, height=31, width=64)
  159.         self.HighN.configure(activebackground="#f9f9f9")
  160.         self.HighN.configure(activeforeground="black")
  161.         self.HighN.configure(background="#d9d9d9")
  162.         self.HighN.configure(disabledforeground="#a3a3a3")
  163.         self.HighN.configure(foreground="#000000")
  164.         self.HighN.configure(highlightbackground="#d9d9d9")
  165.         self.HighN.configure(highlightcolor="black")
  166.         self.HighN.configure(text='''High''')
  167.         self.HighN.configure(width=64)
  168.  
  169.         self.LowN = Label(top)
  170.         self.LowN.place(relx=0.71, rely=0.58, height=31, width=64)
  171.         self.LowN.configure(activebackground="#f9f9f9")
  172.         self.LowN.configure(activeforeground="black")
  173.         self.LowN.configure(background="#d9d9d9")
  174.         self.LowN.configure(disabledforeground="#a3a3a3")
  175.         self.LowN.configure(foreground="#000000")
  176.         self.LowN.configure(highlightbackground="#d9d9d9")
  177.         self.LowN.configure(highlightcolor="black")
  178.         self.LowN.configure(text='''Low''')
  179.         self.LowN.configure(width=64)
  180.  
  181.         self.RandN = Label(top)
  182.         self.RandN.place(relx=0.86, rely=0.58, height=31, width=64)
  183.         self.RandN.configure(activebackground="#f9f9f9")
  184.         self.RandN.configure(activeforeground="black")
  185.         self.RandN.configure(background="#d9d9d9")
  186.         self.RandN.configure(disabledforeground="#a3a3a3")
  187.         self.RandN.configure(foreground="#000000")
  188.         self.RandN.configure(highlightbackground="#d9d9d9")
  189.         self.RandN.configure(highlightcolor="black")
  190.         self.RandN.configure(text='''Rand''')
  191.         self.RandN.configure(width=64)
  192.  
  193.         self.ReRoll = Button(top, command = self.RollRandom)
  194.         self.ReRoll.place(relx=0.82, rely=0.78, height=24, width=87)
  195.         self.ReRoll.configure(activebackground="#d9d9d9")
  196.         self.ReRoll.configure(activeforeground="#000000")
  197.         self.ReRoll.configure(background="#d9d9d9")
  198.         self.ReRoll.configure(disabledforeground="#a3a3a3")
  199.         self.ReRoll.configure(foreground="#000000")
  200.         self.ReRoll.configure(highlightbackground="#d9d9d9")
  201.         self.ReRoll.configure(highlightcolor="black")
  202.         self.ReRoll.configure(pady="0")
  203.         self.ReRoll.configure(text='''Roll Random''')
  204.  
  205.         self.AddEntry = Button(top, command = self.AddEntry)
  206.         self.AddEntry.place(relx=0.41, rely=0.78, height=24, width=87)
  207.         self.AddEntry.configure(activebackground="#d9d9d9")
  208.         self.AddEntry.configure(activeforeground="#000000")
  209.         self.AddEntry.configure(background="#d9d9d9")
  210.         self.AddEntry.configure(disabledforeground="#a3a3a3")
  211.         self.AddEntry.configure(foreground="#000000")
  212.         self.AddEntry.configure(highlightbackground="#d9d9d9")
  213.         self.AddEntry.configure(highlightcolor="black")
  214.         self.AddEntry.configure(pady="0")
  215.         self.AddEntry.configure(text='''Add Entry''')
  216.  
  217.         self.DeleteEntry = Button(top, command = self.DelEntry)
  218.         self.DeleteEntry.place(relx=0.62, rely=0.91, height=24, width=87)
  219.         self.DeleteEntry.configure(activebackground="#d9d9d9")
  220.         self.DeleteEntry.configure(activeforeground="#000000")
  221.         self.DeleteEntry.configure(background="#d9d9d9")
  222.         self.DeleteEntry.configure(disabledforeground="#a3a3a3")
  223.         self.DeleteEntry.configure(foreground="#000000")
  224.         self.DeleteEntry.configure(highlightbackground="#d9d9d9")
  225.         self.DeleteEntry.configure(highlightcolor="black")
  226.         self.DeleteEntry.configure(pady="0")
  227.         self.DeleteEntry.configure(text='''Del Entry''')
  228.  
  229.         self.menubar = Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
  230.         top.configure(menu = self.menubar)
  231.  
  232.  
  233.  
  234.         self.BasePrice = Entry(top)
  235.         self.BasePrice.place(relx=0.41, rely=0.49, relheight=0.1, relwidth=0.12)
  236.         self.BasePrice.configure(background="#c0c0c0")
  237.         self.BasePrice.configure(disabledforeground="#a3a3a3")
  238.         self.BasePrice.configure(font="TkFixedFont")
  239.         self.BasePrice.configure(foreground="#000000")
  240.         self.BasePrice.configure(insertbackground="black")
  241.         self.BasePrice.configure(textvariable="BPVAR")
  242.         self.BasePrice.configure(width=64)
  243.  
  244.         self.HighPrice = Entry(top)
  245.         self.HighPrice.place(relx=0.56, rely=0.49, relheight=0.1, relwidth=0.12)
  246.         self.HighPrice.configure(background="#c0c0c0")
  247.         self.HighPrice.configure(disabledforeground="#a3a3a3")
  248.         self.HighPrice.configure(font="TkFixedFont")
  249.         self.HighPrice.configure(foreground="#000000")
  250.         self.HighPrice.configure(highlightbackground="#d9d9d9")
  251.         self.HighPrice.configure(highlightcolor="black")
  252.         self.HighPrice.configure(insertbackground="black")
  253.         self.HighPrice.configure(selectbackground="#c4c4c4")
  254.         self.HighPrice.configure(selectforeground="black")
  255.         self.HighPrice.configure(textvariable="HVAR")
  256.  
  257.         self.LowPrice = Entry(top)
  258.         self.LowPrice.place(relx=0.71, rely=0.49, relheight=0.1, relwidth=0.12)
  259.         self.LowPrice.configure(background="#c0c0c0")
  260.         self.LowPrice.configure(disabledforeground="#a3a3a3")
  261.         self.LowPrice.configure(font="TkFixedFont")
  262.         self.LowPrice.configure(foreground="#000000")
  263.         self.LowPrice.configure(highlightbackground="#d9d9d9")
  264.         self.LowPrice.configure(highlightcolor="black")
  265.         self.LowPrice.configure(insertbackground="black")
  266.         self.LowPrice.configure(selectbackground="#c4c4c4")
  267.         self.LowPrice.configure(selectforeground="black")
  268.         self.LowPrice.configure(textvariable="LVAR")
  269.  
  270.         self.RandPrice = Entry(top)
  271.         self.RandPrice.place(relx=0.86, rely=0.49, relheight=0.1, relwidth=0.12)
  272.         self.RandPrice.configure(background="#c0c0c0")
  273.         self.RandPrice.configure(disabledforeground="#a3a3a3")
  274.         self.RandPrice.configure(font="TkFixedFont")
  275.         self.RandPrice.configure(foreground="#000000")
  276.         self.RandPrice.configure(highlightbackground="#d9d9d9")
  277.         self.RandPrice.configure(highlightcolor="black")
  278.         self.RandPrice.configure(insertbackground="black")
  279.         self.RandPrice.configure(selectbackground="#c4c4c4")
  280.         self.RandPrice.configure(selectforeground="black")
  281.         self.RandPrice.configure(textvariable="RVAR")
  282.         self.RandPrice.configure(width=64)
  283.  
  284.         self.Description = Text(top)
  285.         self.Description.place(relx=0.41, rely=0.03, relheight=0.43
  286.                 , relwidth=0.57)
  287.         self.Description.configure(background="#c0c0c0")
  288.         self.Description.configure(font="TkTextFont")
  289.         self.Description.configure(foreground="black")
  290.         self.Description.configure(highlightbackground="#d9d9d9")
  291.         self.Description.configure(highlightcolor="black")
  292.         self.Description.configure(insertbackground="black")
  293.         self.Description.configure(selectbackground="#c4c4c4")
  294.         self.Description.configure(selectforeground="black")
  295.         self.Description.configure(width=304)
  296.         self.Description.configure(wrap=WORD)
  297.        
  298.     def RollRandom(self):
  299.         desc = self.Description.get('1.0','end-1c')
  300.         name = desc.split(':')
  301.         high = self.HighPrice.get()
  302.         low = self.LowPrice.get()
  303.        
  304.         if high == '' or low == '':
  305.             for index, sublist in enumerate(self.ItemList):
  306.                 if sublist[0] == name[0]:
  307.                     sublist[5] = random.randint(int(sublist[4]),int(sublist[3]))
  308.                     self.RandPrice.delete('0',END)
  309.                     self.RandPrice.insert(END,sublist[5])
  310.         else:
  311.             randNum = random.randint(int(low),int(high))
  312.             self.RandPrice.delete('0',END)
  313.             self.RandPrice.insert(END,randNum)
  314.     def AddEntry(self):
  315.         self.Description.delete('1.0',END)
  316.         self.BasePrice.delete('0',END)
  317.         self.HighPrice.delete('0',END)
  318.         self.LowPrice.delete('0',END)
  319.         self.RandPrice.delete('0',END)
  320.        
  321.    
  322.     def DelEntry(self, *args):
  323.         desc = self.Description.get('1.0','end-1c')
  324.         name = desc.split(':')
  325.         for index, sublist in enumerate(self.ItemList):
  326.             if sublist[0] == name[0]:
  327.                 del self.ItemList[index]
  328.                 self.ShopInventory.delete(0, END)
  329.                 names = [item[0] for item in self.ItemList]
  330.                 for aName in names:
  331.                     self.ShopInventory.insert(END, aName)
  332.                    
  333.         self.Description.delete('1.0',END)
  334.         self.BasePrice.delete('0',END)
  335.         self.HighPrice.delete('0',END)
  336.         self.LowPrice.delete('0',END)
  337.         self.RandPrice.delete('0',END)
  338.                    
  339.     def SaveEntry(self, *args):
  340.         desc = self.Description.get('1.0','end-1c')      
  341.         name = desc.split(":")
  342.         for index, sublist in enumerate(self.ItemList): #CHECKS IF DUPLICATE SUBLIST IS IN LIST
  343.             if sublist[0] == name[0]:
  344.                 del self.ItemList[index]
  345.                 self.ShopInventory.delete(0, END)
  346.                 names = [item[0] for item in self.ItemList]
  347.                 for aName in names:
  348.                     self.ShopInventory.insert(END, aName)
  349.           #######################################################THIS IS WHERE I WAS
  350.         base = self.BasePrice.get()
  351.         high = self.HighPrice.get()
  352.         low = self.LowPrice.get()
  353.         rand = self.RandPrice.get()
  354.         item = [name[0],desc,base,high,low,rand]
  355.         self.ItemList.append(item)      
  356.         self.Description.delete('1.0', END)
  357.         self.BasePrice.delete('0', END)
  358.         self.HighPrice.delete('0', END)
  359.         self.LowPrice.delete('0', END)
  360.         self.RandPrice.delete('0', END)
  361.         self.ShopInventory.insert(END, str(name[0]))
  362.  
  363.     def ExportFile(self):
  364.         f = filedialog.asksaveasfilename(title = "Save As - DO NOT EDIT .XLSX MANUALLY",filetypes=(("Spreadsheet", "*.xlsx"),("All Files","*.*")))
  365.         if f == '':
  366.             return
  367.         else:
  368.  
  369.             CheckString = ".xlsx"
  370.             if CheckString in f:
  371.                 workbook = xlsxwriter.Workbook(f)
  372.             else:
  373.                 workbook = xlsxwriter.Workbook(f + ".xlsx")
  374.  
  375.             bold = workbook.add_format({'bold': True})
  376.             text_format = workbook.add_format({'text_wrap': True})
  377.             worksheet = workbook.add_worksheet()
  378.             worksheet.set_column('B:B',38)
  379.             worksheet.set_column('A:A',15)
  380.             worksheet.write(0,0, "Name", bold)
  381.             worksheet.write(0,1, "Description", bold)
  382.             worksheet.write(0,2, "Base $", bold)
  383.             worksheet.write(0,3, "High $", bold)
  384.             worksheet.write(0,4, "Low $", bold)
  385.             worksheet.write(0,5, "Rand $", bold)
  386.             row = 1
  387.             col = 0
  388.             for llist in self.ItemList:
  389.                 for item in llist:
  390.                     descCheck = ":" in item
  391.                     if descCheck:
  392.                         print(descCheck)
  393.                         item = item.split(":",1)[-1]
  394.                        
  395.                     worksheet.write(row,col, item, text_format)
  396.                     col +=1
  397.                 row +=1
  398.                 col = 0
  399.             workbook.close()
  400.  
  401.             if CheckString in f:
  402.                 messagebox.showinfo("Export Successful", f.rsplit("/",1)[-1] + " created")
  403.             else:
  404.                 messagebox.showinfo("Export Successful", f.rsplit("/",1)[-1] + ".xlsx created")
  405.            
  406.     def ImportFile(self):
  407.  
  408.         def _itersplit(fin, splitters):
  409.             current = []
  410.             for item in fin:
  411.                 if item in splitters:
  412.                     yield current
  413.                     current = []
  414.                 else:
  415.                     current.append(item)
  416.             yield current
  417.  
  418.         def magicsplit(fin, *splitters):
  419.             return [subl for subl in _itersplit(fin, splitters) if subl]
  420.  
  421.         f = filedialog.askopenfilename(filetypes =(("Spreadsheet","*.xlsx"),("All Files","*.*")))
  422.         if f == "":
  423.             return
  424.         else:
  425.             try:
  426.                 wb = openpyxl.load_workbook(f)
  427.                 ws = wb.active
  428.                 pre = []
  429.                 for row in ws.iter_rows(row_offset=1):
  430.                     if len(pre) != 0:
  431.                         pre.append(None)
  432.                     for cell in row:
  433.                         value = cell.value
  434.                        
  435.                         if value is None:
  436.                             print("in none!")
  437.                             pass
  438.                         else:
  439.                             pre.append(value)
  440.  
  441.                 del pre[-1]
  442.                 it = magicsplit(pre, None)
  443.                 print(str(it))
  444.                 for alist in it:
  445.                     alist[1] = alist[0]+":"+alist[1]
  446.                     del self.ItemList[:]
  447.                     self.ItemList.append(it)
  448.                     self.ShopInventory.delete(0, END)
  449.                     self.Description.delete('1.0', END)
  450.                     self.BasePrice.delete('0', END)
  451.                     self.HighPrice.delete('0', END)
  452.                     self.LowPrice.delete('0', END)
  453.                     self.RandPrice.delete('0', END)
  454.                     names = [item[0] for item in self.ItemList[0]]
  455.                     for aName in names:
  456.                         self.ShopInventory.insert(END, aName)
  457.             except Exception as e:
  458.                 messagebox.showinfo("Import Failed","Spreadsheet may be damaged or corrupted. Merged cells can also raise exceptions")
  459.                 pass
  460.  
  461.     @staticmethod
  462.     def popup1(event):
  463.         Popupmenu1 = Menu(root, tearoff=0)
  464.         Popupmenu1.configure(activebackground="#f9f9f9")
  465.         Popupmenu1.configure(activeborderwidth="1")
  466.         Popupmenu1.configure(activeforeground="black")
  467.         Popupmenu1.configure(background="#d9d9d9")
  468.         Popupmenu1.configure(borderwidth="1")
  469.         Popupmenu1.configure(disabledforeground="#a3a3a3")
  470.         Popupmenu1.configure(font="{Segoe UI} 9")
  471.         Popupmenu1.configure(foreground="black")
  472.         Popupmenu1.post(event.x_root, event.y_root)
  473.  
  474.  
  475.  
  476.  
  477.  
  478. # The following code is added to facilitate the Scrolled widgets you specified.
  479. class AutoScroll(object):
  480.     '''Configure the scrollbars for a widget.'''
  481.  
  482.     def __init__(self, master):
  483.         #  Rozen. Added the try-except clauses so that this class
  484.         #  could be used for scrolled entry widget for which vertical
  485.         #  scrolling is not supported. 5/7/14.
  486.         try:
  487.             vsb = ttk.Scrollbar(master, orient='vertical', command=self.yview)
  488.         except:
  489.             pass
  490.         hsb = ttk.Scrollbar(master, orient='horizontal', command=self.xview)
  491.  
  492.         #self.configure(yscrollcommand=_autoscroll(vsb),
  493.         #    xscrollcommand=_autoscroll(hsb))
  494.         try:
  495.             self.configure(yscrollcommand=self._autoscroll(vsb))
  496.         except:
  497.             pass
  498.         self.configure(xscrollcommand=self._autoscroll(hsb))
  499.  
  500.         self.grid(column=0, row=0, sticky='nsew')
  501.         try:
  502.             vsb.grid(column=1, row=0, sticky='ns')
  503.         except:
  504.             pass
  505.         hsb.grid(column=0, row=1, sticky='ew')
  506.  
  507.         master.grid_columnconfigure(0, weight=1)
  508.         master.grid_rowconfigure(0, weight=1)
  509.  
  510.         # Copy geometry methods of master  (taken from ScrolledText.py)
  511.         if py3:
  512.             methods = Pack.__dict__.keys() | Grid.__dict__.keys() \
  513.                   | Place.__dict__.keys()
  514.         else:
  515.             methods = Pack.__dict__.keys() + Grid.__dict__.keys() \
  516.                   + Place.__dict__.keys()
  517.  
  518.         for meth in methods:
  519.             if meth[0] != '_' and meth not in ('config', 'configure'):
  520.                 setattr(self, meth, getattr(master, meth))
  521.  
  522.     @staticmethod
  523.     def _autoscroll(sbar):
  524.         '''Hide and show scrollbar as needed.'''
  525.         def wrapped(first, last):
  526.             first, last = float(first), float(last)
  527.             if first <= 0 and last >= 1:
  528.                 sbar.grid_remove()
  529.             else:
  530.                 sbar.grid()
  531.             sbar.set(first, last)
  532.         return wrapped
  533.  
  534.     def __str__(self):
  535.         return str(self.master)
  536.  
  537. def _create_container(func):
  538.     '''Creates a ttk Frame with a given master, and use this new frame to
  539.    place the scrollbars and the widget.'''
  540.     def wrapped(cls, master, **kw):
  541.         container = ttk.Frame(master)
  542.         return func(cls, container, **kw)
  543.     return wrapped
  544.  
  545. class ScrolledListBox(AutoScroll, Listbox):
  546.     '''A standard Tkinter Text widget with scrollbars that will
  547.    automatically show/hide as needed.'''
  548.     @_create_container
  549.     def __init__(self, master, **kw):
  550.         Listbox.__init__(self, master, **kw)
  551.         AutoScroll.__init__(self, master)
  552.  
  553. if __name__ == '__main__':
  554.     vp_start_gui()
  555.  
  556. !-----"Setup.py"-----! #CREATE EXECUTABLE
  557. from cx_Freeze import setup, Executable
  558. import cx_Freeze
  559. import os.path
  560. import xlsxwriter
  561. import pyexcel
  562. import random
  563. import openpyxl
  564. import sys
  565. PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
  566. os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
  567. os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
  568. base = None    
  569. if sys.platform == 'win32':
  570.     base = "Win32GUI"
  571.    
  572. executables = [Executable("OneStopShop.py", base=base, icon="icon.ico")]
  573.  
  574. cx_Freeze.setup(
  575. name = "OneStop",
  576. executables = executables,
  577. description = "Tabletop tool by REED",
  578. options = {
  579.     'build_exe': {    
  580.         'include_files':[
  581.             os.path.join(PYTHON_INSTALL_DIR, 'DLLs' , 'tk86t.dll'),
  582.             os.path.join(PYTHON_INSTALL_DIR, 'DLLs' , 'tcl86t.dll'),
  583.             "icon.ico"],
  584.             'packages':["sys","random","xlsxwriter","pyexcel","tkinter","openpyxl"]
  585.     }}  
  586.  
  587. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement