文本插入后Tkinter窗口无响应

时间:2017-04-24 04:48:24

标签: python python-3.x user-interface tkinter

我是Python新手,刚刚开始尝试使用GUI。我创建了一个非常基本的Tkinter窗口:它有3个Entry栏和3个File Dialog按钮。当您选择第3个目录时,GUI文件会自动调用单独的文件并接收一个大文本块,然后在文本框中显示。

整个过程正常,但我的问题是,在接收并插入文本响应后,Tkinter停止工作,并且不允许用户向下滚动。

我读到发生这种情况的一个原因是人们同时使用.pack( ).grid( ),但我并没有将这两个功能混合在一起。

提前感谢您的帮助!

这是我的GUI文件

from tkinter import *
from tkinter import filedialog
from gui_GPSExtractor import *
import os


class Application(Frame):

    def __init__(self, master):
        """ Initialize Frame """
        Frame.__init__(self, master)
        self.grid( )
        self.startGUI( )

    """ Create Labels, Text Boxes, File Dialogs, and Buttons """
    def startGUI(self):
        # Label for Scan Path
        self.dLabel = Label(self, text = "Scan Path")
        self.dLabel.grid(row = 0, column = 0, columnspan = 2, sticky = W)

        # Entry for Scan Path
        self.dEntry = Entry(self, width = 60)
        self.dEntry.grid(row = 1, column = 0, sticky = W)

        # Button for Scan Path Directory Browse
        self.dButton = Button(self, text = "Browse", command = lambda: self.browseFiles("d"))
        self.dButton.grid(row = 1, column = 1, sticky = W)

        # Label for CSV Path
        self.cLabel = Label(self, text = "CSV Path")
        self.cLabel.grid(row = 3, column = 0, columnspan = 2, sticky = W)

        # Entry for CSV Path
        self.cEntry = Entry(self, width = 60)
        self.cEntry.grid(row = 4, column = 0, sticky = W)

        # Button for CSV Path Directory Browse
        self.cButton = Button(self, text = "Browse", command = lambda: self.browseFiles("c"))
        self.cButton.grid(row = 4, column = 1, sticky = W)

        # Label for Log Path
        self.lLabel = Label(self, text = "Log Path")
        self.lLabel.grid(row = 6, column = 0, columnspan = 2, sticky = W)

        # Entry for Log Path
        self.lEntry = Entry(self, width = 60)
        self.lEntry.grid(row = 7, column = 0, sticky = W)

        # Button for Log Path Directory Browse
        self.lButton = Button(self, text = "Browse", command = lambda: self.browseFiles("l"))
        self.lButton.grid(row = 7, column = 1, sticky = W)

        # Text Box for Results
        self.resultText = Text(self, width = 60, height = 30, wrap = WORD, borderwidth = 3, relief = SUNKEN)
        self.resultText.grid(row = 9, column = 0, columnspan = 2, sticky = "nsew")

        # Scrollbar for Text Box
        self.scrollBar = Scrollbar(self, command = self.resultText.yview)
        self.scrollBar.grid(row = 9, column = 2, sticky = "nsew")
        self.resultText["yscrollcommand"] = self.scrollBar.set

    def browseFiles(self, btnCalling):
        if(btnCalling == "d"):
            self.dName = filedialog.askdirectory(initialdir = "/python3-CH05")
            self.dEntry.delete(0, END)
            self.dEntry.insert(0, self.dName)
        elif(btnCalling == "c"):
            self.cName = filedialog.askdirectory(initialdir = "/python3-CH05")
            self.cEntry.delete(0, END)
            self.cEntry.insert(0, self.cName)
        elif(btnCalling == "l"):
            self.lName = filedialog.askdirectory(initialdir = "/python3-CH05")
            self.lEntry.delete(0, END)
            self.lEntry.insert(0, self.lName)
            output = extractGPS(self.dName, self.cName, self.lName)
            self.resultText.delete(0.0, END)
            self.resultText.insert(0.0, output)

# Start the GUI
root = Tk( )
root.title("Python gpsExtractor")
root.geometry("650x650")
app = Application(root)
root.mainloop( )

0 个答案:

没有答案