0

I am trying to make a browse button for a GUI to test for accuracy. The button come in perfectly as well as the entry widget. I use tkFileDialog.askopenfilename() which opens the dialog box and allows me to select a file.

When I click open though nothing no text shows up in the entry widget though it would seem that the script is recognizing a file in the widget. I don't know how the text became invisible.

I have done a fair amount of research and tweaking to get this to work and nothing I try on my own or from the research seems to work. It is probably a quick fix and I am over thinking it.

import tkFileDialog
from Tkinter import *



LARGE_FONT = ("Times New Roman", 18)
FONT = ("Times New Roman", 12)
background = "#A8A8A8"

def set_text(text, File):
    File.delete(0, "end")
    File.insert(0, text)
    return

class AccuracyAssessmentApp:
    #The main function
    def __init__(self, parent=Tk()):
        self.mainWindow = (parent)
        self.mainWindow.title("Accuracy Assessment")
        self.mainWindow.geometry("1000x700")
        self.make_txt()
        self.browse()



    #Set the text for the main window
    def make_txt(self):
        self.text = Text(self.mainWindow, width = 80, height = 40, background = background)
        self.text.pack(expand = TRUE, fill = BOTH)

    def browse(self):
        self.inputRaster = Entry(self.mainWindow,  width=70).place(x=5,y=150)
        Button(self.mainWindow, text="Input", command=lambda: set_text(tkFileDialog.askopenfilename(), self.inputRaster)).place(x=575,y=150)        


app = AccuracyAssessmentApp()
app.mainWindow.mainloop()
Jake
  • 303
  • 5
  • 19
  • what does `AAM.set_text` do? Also, clearly this code won't run as it calls non-existent functions, and the indentation is incorrect. Please read http://www.stackoverflow.com/help/mcve – Bryan Oakley Jun 27 '16 at 13:54
  • Sorry AAM is a custom function I built: def set_text(text, File): File.delete(o,"end") File.insert(0, text) return Those function do exist I just left them out because it would be way to long to have it all here. What is wrong with the indentations? They work fine for me and I have no errors. – Jake Jun 27 '16 at 14:40
  • What is wrong with the indentation? `class` is indented the same as the methods under it. If we can't run your code to reproduce the problem it greatly diminishes our chance to help you. You need to provide a minimal program that illustrates the problem. Remove all functions that are completely unrelated to the problem. – Bryan Oakley Jun 27 '16 at 15:20
  • Sorry I didn't realize the code got messed up when I posted it. I'll re-post the code – Jake Jun 27 '16 at 15:31
  • I uploaded a new code that should show the button and the issue with the bare minimum. If you run and click on the input button you should get the askopenfile dialogue box and when you open the file no text. - @Bryan Oakley – Jake Jun 27 '16 at 15:49
  • I get an error when I select the file. Are you not seeing an error? – Bryan Oakley Jun 27 '16 at 16:16
  • The problem is this line: `self.inputRaster = Entry(self.mainWindow, width=70).place(x=5,y=150)` because of this: http://stackoverflow.com/q/1101750/7432 – Bryan Oakley Jun 27 '16 at 16:17
  • Dividing the line up shown in that link works perfectly. Thanks – Jake Jun 27 '16 at 16:38

0 Answers0