Python Forum
Storing the result of a input field
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Storing the result of a input field
#1
I have an input field for a filepath in my script so the user can direct the script to a required spreadsheets location.

As this filepath is different PC to PC I want to store the last entered filepath as a default in the input field so once a user has entered the filepath the last file location is saved and only needs to be changed if on a different PC then again once its changed it is saved as default again etc etc.

My current work round to this is a default filepath actually in the code but what i want is when the user enters a new filepath that becomes the new default, even after the script is closed.

How is this possible to store this new default filepath ???

Initial research has brought the Shelve module to my attention but i dont know if this is the best solution

#GUI Variables
IPT1 = Entry(IPT)
#GUI Screen widgets
IPT_Lab1 = Label(IPT, text="filepath : ", anchor=W)
#Default Filepath entry
IPT1.insert(0, r"C:\Users\x\y\z\spreadsheet.xlsx")
Reply
#2
show complete code, not enough here to properly answer
Reply
#3
#Import Panda module for Excel interogation
import pandas as pd
#Import TKinter module for GUI
import tkinter as tk
from tkinter import messagebox
from tkinter import *

#Create GUI Screen
TCM = Tk()
TCM.title("TCM Connect")
canvas_TCM = Canvas(TCM, width=301, height=301)
canvas_TCM.pack()

#Function for TCM Connect button
def TCM_CON():
    print("Test")

#Function for Load Data Button
def entry_field():
    print("Filepath: %s" % (TCM1.get()))
    print("Asset No: %s" % (TCM2.get()))

    #Import Excel Spreadsheet - IP Plan

    excel_sheet = TCM1.get()
    IP_Plan = pd.read_excel(excel_sheet)

    IP_Plan.head()

    #Required column's as vectors
    IP_Plan["Station name"]
    IP_Plan["Type"]
    IP_Plan["IP address"]

    #Filter rows by column E (Station name) for results with cell = Asset No. 
    xlsx_filter1 = IP_Plan.index[IP_Plan['Station name'] == TCM2.get()].tolist()
    IP_Plan=IP_Plan.loc[xlsx_filter1]

    #Filter rows by column C (Type) for results with cell = Device Type 
    xlsx_filter2 = IP_Plan.index[IP_Plan['Type'] == "System"].tolist()
    IP_Plan=IP_Plan.loc[xlsx_filter2]

    #File cell value by column B (IP address)
    Output_IP_Address_TCM = list( IP_Plan["IP address"])
    print(Output_IP_Address_TCM)

    TCM_Display = Label(TCM, text=Output_IP_Address_TCM, anchor=W)
    TCM_Display = canvas_TCM.create_window(150, 210, anchor = 'sw', window = TCM_Display)

#GUI Variables
TCM1 = Entry(TCM)
TCM2 = Entry(TCM)
#GUI Screen widgets
TCM_Lab1 = Label(TCM, text="filepath : ", anchor=W)
TCM_Lab1_Window = canvas_TCM.create_window(20, 90, anchor = 'sw', window = TCM_Lab1)

TCM_Lab2 = Label(TCM, text="Asset Number : ", anchor=W)
TCM_Lab2_Window = canvas_TCM.create_window(20, 110, anchor = 'sw', window = TCM_Lab2)

TCM1_Window = canvas_TCM.create_window(150, 90, anchor = 'sw', window = TCM1)
TCM2_Window = canvas_TCM.create_window(150, 110, anchor = 'sw', window = TCM2)

#Default Filepath entry
TCM1.insert(0, r"C:\Users\x\y\z\Spreadsheet.xlsx")

#Button
TCMLoad_Button = tk.Button(TCM, text = 'Load Data', command = entry_field, background ="#01AEAC", width=12, height=2,)
TCMAccept_Button_Window = canvas_TCM.create_window(20, 170, anchor = 'sw', window = TCMLoad_Button)
TCMCON_Button = tk.Button(TCM, text = 'Connect', command = TCM_CON, background ="#01AEAC", width=12, height=2,)
TCMCON_Button_Window = canvas_TCM.create_window(20, 220, anchor = 'sw', window = TCMCON_Button)

TCM.mainloop()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020