Python tkFileDialog 模块,Open() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用tkFileDialog.Open()

项目:JetsonTX1_im2txt    作者:Netzeband    | 项目源码 | 文件源码
def _openImage(self):
    FileTypes = [('JPG Image Files', '*.jpg'), ('All files', '*')]
    Dialog = tkFileDialog.Open(self._ControlFrame, filetypes = FileTypes)
    FileName = Dialog.show()

    if not FileName == '' and not FileName == ():
      print("Open file: "+str(FileName))

      if self._IsVideoRunnung:
        self._pressPause()

      Image = image.open(FileName)
      Image = Image.resize(self._getLabelSize(self._VideoLabel, Image.width/Image.height), image.ANTIALIAS)
      Image = imagetk.PhotoImage(Image)
      self._VideoLabel.imgtk = Image
      self._VideoLabel.configure(image=Image)          

      self._OutputText.delete('1.0', tk.END)

      File = tf.gfile.GFile(FileName, "r")
      Captions = self._CaptionFunc(File.read())

      for i, Caption in enumerate(Captions):
        self._OutputText.insert(tk.END, str(i+1)+") "+Caption+"\n")
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def browseFile(self):
        filetypes = [
            ("HTML Files", "*.htm *.html", "TEXT"),
            ("PDF Files", "*.pdf", "TEXT"),
            ("Windows Help Files", "*.chm"),
            ("Text Files", "*.txt", "TEXT"),
            ("All Files", "*")]
        path = self.path.get()
        if path:
            dir, base = os.path.split(path)
        else:
            base = None
            if sys.platform[:3] == 'win':
                dir = os.path.join(os.path.dirname(sys.executable), 'Doc')
                if not os.path.isdir(dir):
                    dir = os.getcwd()
            else:
                dir = os.getcwd()
        opendialog = tkFileDialog.Open(parent=self, filetypes=filetypes)
        file = opendialog.show(initialdir=dir, initialfile=base)
        if file:
            self.path.set(file)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def browseFile(self):
        filetypes = [
            ("HTML Files", "*.htm *.html", "TEXT"),
            ("PDF Files", "*.pdf", "TEXT"),
            ("Windows Help Files", "*.chm"),
            ("Text Files", "*.txt", "TEXT"),
            ("All Files", "*")]
        path = self.path.get()
        if path:
            dir, base = os.path.split(path)
        else:
            base = None
            if sys.platform[:3] == 'win':
                dir = os.path.join(os.path.dirname(sys.executable), 'Doc')
                if not os.path.isdir(dir):
                    dir = os.getcwd()
            else:
                dir = os.getcwd()
        opendialog = tkFileDialog.Open(parent=self, filetypes=filetypes)
        file = opendialog.show(initialdir=dir, initialfile=base)
        if file:
            self.path.set(file)
项目:SUTDAnnotator    作者:jiesutd    | 项目源码 | 文件源码
def onOpen(self):
        ftypes = [('all files', '.*'), ('text files', '.txt'), ('ann files', '.ann')]
        dlg = tkFileDialog.Open(self, filetypes = ftypes)
        # file_opt = options =  {}
        # options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        # dlg = tkFileDialog.askopenfilename(**options)
        fl = dlg.show()
        if fl != '':
            self.text.delete("1.0",END)
            text = self.readFile(fl)
            self.text.insert(END, text)
            self.setNameLabel("File: " + fl)
            self.autoLoadNewFile(self.fileName, "1.0")
            # self.setDisplay()
            # self.initAnnotate()
            self.text.mark_set(INSERT, "1.0")
            self.setCursorLabel(self.text.index(INSERT))
项目:SUTDAnnotator    作者:jiesutd    | 项目源码 | 文件源码
def onOpen(self):
        ftypes = [('all files', '.*'), ('text files', '.txt'), ('ann files', '.ann')]
        dlg = tkFileDialog.Open(self, filetypes = ftypes)
        # file_opt = options =  {}
        # options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        # dlg = tkFileDialog.askopenfilename(**options)
        fl = dlg.show()
        if fl != '':
            self.text.delete("1.0",END)
            text = self.readFile(fl)
            self.text.insert(END, text)
            self.setNameLabel("File: " + fl)
            self.setDisplay()
            # self.initAnnotate()
            self.text.mark_set(INSERT, "1.0")
            self.setCursorLabel(self.text.index(INSERT))
项目:PyLanMessenger    作者:stoic1979    | 项目源码 | 文件源码
def add_menus(self):
        menubar = Menu(self.parent)

        # create a pulldown menu, and add it to the menu bar
        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open", command=self.hello)
        filemenu.add_command(label="Save", command=self.hello)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=self.parent.quit)
        menubar.add_cascade(label="File", menu=filemenu)

        # create more pulldown menus
        editmenu = Menu(menubar, tearoff=0)
        editmenu.add_command(label="Cut", command=self.hello)
        editmenu.add_command(label="Copy", command=self.hello)
        editmenu.add_command(label="Paste", command=self.hello)
        menubar.add_cascade(label="Edit", menu=editmenu)

        helpmenu = Menu(menubar, tearoff=0)
        helpmenu.add_command(label="About", command=self.hello)
        menubar.add_cascade(label="Help", menu=helpmenu)

        # display the menu
        self.parent.config(menu=menubar)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def browseFile(self):
        filetypes = [
            ("HTML Files", "*.htm *.html", "TEXT"),
            ("PDF Files", "*.pdf", "TEXT"),
            ("Windows Help Files", "*.chm"),
            ("Text Files", "*.txt", "TEXT"),
            ("All Files", "*")]
        path = self.path.get()
        if path:
            dir, base = os.path.split(path)
        else:
            base = None
            if sys.platform[:3] == 'win':
                dir = os.path.join(os.path.dirname(sys.executable), 'Doc')
                if not os.path.isdir(dir):
                    dir = os.getcwd()
            else:
                dir = os.getcwd()
        opendialog = tkFileDialog.Open(parent=self, filetypes=filetypes)
        file = opendialog.show(initialdir=dir, initialfile=base)
        if file:
            self.path.set(file)
项目:image-copy-move-detection    作者:rahmatnazali    | 项目源码 | 文件源码
def onDetect(self):
        if self.imageName == "":
            mbox.showerror("Error", 'Citra masukan belum terisi\nSilakan pilih dengan menekan tombol "Open File"')
        else:

            self.textBoxLog.config(state='normal')
            self.textBoxLog.insert(END, "Mendeteksi: "+self.imageName+"\n")
            self.textBoxLog.see(END)
            self.textBoxLog.config(state='disabled')

            imageResultPath = CopyMoveDetection.detect(self.imagePath, self.imageName, '../testcase_result/', blockSize=32)
            newImageRight = Image.open(imageResultPath)
            imageRightLabel = ImageTk.PhotoImage(newImageRight)
            self.labelRight = Label(self, image=imageRightLabel)
            self.labelRight.image = imageRightLabel
            self.labelRight.place(x=525, y=100)

            self.textBoxLog.config(state='normal')
            self.textBoxLog.insert(END, "Selesai.")
            self.textBoxLog.see(END)
            self.textBoxLog.config(state='disabled')
            pass
        pass
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def askopenfile(self):
        dir, base = self.defaultfilename("open")
        if not self.opendialog:
            self.opendialog = tkFileDialog.Open(parent=self.text,
                                                filetypes=self.filetypes)
        filename = self.opendialog.show(initialdir=dir, initialfile=base)
        if isinstance(filename, unicode):
            filename = filename.encode(filesystemencoding)
        return filename
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def askopenfile(self):
        dir, base = self.defaultfilename("open")
        if not self.opendialog:
            self.opendialog = tkFileDialog.Open(parent=self.text,
                                                filetypes=self.filetypes)
        filename = self.opendialog.show(initialdir=dir, initialfile=base)
        if isinstance(filename, unicode):
            filename = filename.encode(filesystemencoding)
        return filename
项目:PyLanMessenger    作者:stoic1979    | 项目源码 | 文件源码
def send_file(self):
        file_types = [('All files', '*')]
        open = tkFileDialog.Open(self.root, filetypes = file_types)
        statusbar = Label(self.root, text="", bd=1, relief=SUNKEN, anchor=W)
        statusbar.pack(side=BOTTOM, fill=X)
        file_path = open.show()
        statusbar.config(text = file_path)
        print "Will send file", file_path


#########################
#   STARTING MAIN GUI   #
#########################
项目:FFT-spectrum-analyzer    作者:ariquezada    | 项目源码 | 文件源码
def open_file(self):
        """Opens dialog to select a file, reads data from file and plots the data"""
        ftypes = [('Text files', '*.txt'), ('All files', '*')]
        dlg = tkFileDialog.Open(root, filetypes = ftypes)
        fl = dlg.show()
        if fl != '':
            # Open file for reading
            arch = open(fl, "r")
            datos_arch = arch.read()
            # Searches for every channel, delimited by L1, L2 and L3 tags.
            canal_1 = extraer_int_tag(datos_arch, 'L1')
            canal_2 = extraer_int_tag(datos_arch, 'L2')
            canal_3 = extraer_int_tag(datos_arch, 'L3')

            print("Amount of samples in channel 1: %s" %len(canal_1))
            print("Amount of samples on channel 2: %s" %len(canal_2))
            print("Amount of samples on channel 3: %s" %len(canal_3))
            message_string = "Amount of samples channel 1: {0} \n".format(len(canal_1))
            message_string += "Amount of samples channel 2: {0} \n".format(len(canal_2))
            message_string += "Amount of samples channel 3: {0} \n".format(len(canal_3))
            self.show_message(self.text_message, message_string)

            global g_canal_1, g_canal_2, g_canal_3
            #Keep a copy of the original values
            g_canal_1 = canal_1[:]            #Copy list by value not by reference
            g_canal_2 = canal_2[:]
            g_canal_3 = canal_3[:]

            self.window_var.set(1)        #Option rectangular window
            self.plot(self.tab1, self.tab2, canal_1, canal_2, canal_3, win_var=1)
项目:FFT-spectrum-analyzer    作者:ariquezada    | 项目源码 | 文件源码
def open_file(self):
        """Opens dialog to select a file, reads data from file and plots the data"""
        ftypes = [('Text files', '*.txt'), ('All files', '*')]
        dlg = tkFileDialog.Open(root, filetypes = ftypes)
        fl = dlg.show()
        if fl != '':
            # Open file for reading
            arch = open(fl, "r")
            datos_arch = arch.read()
            # Searches for every channel, delimited by L1 and L2 tags.
            canal_1 = extraer_int_tag(datos_arch, 'L1')
            canal_2 = extraer_int_tag(datos_arch, 'L2')

            print("Amount of samples in channel 1: %s" %len(canal_1))
            print("Amount of samples on channel 2: %s" %len(canal_2))
            message_string = "Amount of samples channel 1: {0} \n".format(len(canal_1))
            message_string += "Amount of samples channel 2: {0} \n".format(len(canal_2))
            self.show_message(self.text_message, message_string)

            global g_canal_1, g_canal_2
            #Keep a copy of the original values
            g_canal_1 = canal_1[:]            #Copy list by value not by reference
            g_canal_2 = canal_2[:]

            self.window_var.set(1)        #Option rectangular window
            self.plot(self.tab1, self.tab2, canal_1, canal_2, win_var=1)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def askopenfile(self):
        dir, base = self.defaultfilename("open")
        if not self.opendialog:
            self.opendialog = tkFileDialog.Open(master=self.text,
                                                filetypes=self.filetypes)
        filename = self.opendialog.show(initialdir=dir, initialfile=base)
        if isinstance(filename, unicode):
            filename = filename.encode(filesystemencoding)
        return filename
项目:image-copy-move-detection    作者:rahmatnazali    | 项目源码 | 文件源码
def initUI(self):
        self.parent.title("Image Copy-Move Detection")
        self.style = Style().configure("TFrame", background="#333")
        # self.style.theme_use("default")
        self.pack(fill=BOTH, expand=1)

        quitButton = Button(self, text="Open File", command=self.onFilePicker)
        quitButton.place(x=10, y=10)

        printButton = Button(self, text="Detect", command=self.onDetect)
        printButton.place(x=10, y=40)

        self.textBoxFile = Text(self, state='disabled', width=80, height = 1)
        self.textBoxFile.place(x=90, y=10)

        self.textBoxLog = Text(self, state='disabled', width=40, height=3)
        self.textBoxLog.place(x=90, y=40)

        # absolute image widget
        imageLeft = Image.open("resource/empty.png")
        imageLeftLabel = ImageTk.PhotoImage(imageLeft)
        self.labelLeft = Label(self, image=imageLeftLabel)
        self.labelLeft.image = imageLeftLabel
        self.labelLeft.place(x=5, y=100)

        imageRight = Image.open("resource/empty.png")
        imageRightLabel = ImageTk.PhotoImage(imageRight)
        self.labelRight = Label(self, image=imageRightLabel)
        self.labelRight.image = imageRightLabel
        self.labelRight.place(x=525, y=100)


        self.centerWindow()
项目:image-copy-move-detection    作者:rahmatnazali    | 项目源码 | 文件源码
def onFilePicker(self):

        ftypes = [('PNG Files', '*.png'), ('All files', '*')]
        dlg = tkFileDialog.Open(self, initialdir='../testcase_image/', filetypes = ftypes)
        choosedFile = dlg.show()

        if choosedFile != '':
            print choosedFile
            self.imageName = str(choosedFile).split("/")[-1]
            self.imagePath = str(choosedFile).replace(self.imageName, '')

            self.textBoxFile.config(state='normal')
            self.textBoxFile.delete('1.0', END)
            self.textBoxFile.insert(END, choosedFile)
            self.textBoxFile.config(state='disabled')

            newImageLeft = Image.open(choosedFile)
            imageLeftLabel = ImageTk.PhotoImage(newImageLeft)
            self.labelLeft = Label(self, image=imageLeftLabel)
            self.labelLeft.image = imageLeftLabel
            self.labelLeft.place(x=5, y=100)

            imageRight = Image.open("resource/empty.png")
            imageRightLabel = ImageTk.PhotoImage(imageRight)
            self.labelRight = Label(self, image=imageRightLabel)
            self.labelRight.image = imageRightLabel
            self.labelRight.place(x=525, y=100)

        pass
项目:JetsonTX1_im2txt    作者:Netzeband    | 项目源码 | 文件源码
def __init__(self, VideoStream, CaptionFunc = None):
    self._CaptionFunc = CaptionFunc
    self._VideoStream = VideoStream

    # Set up GUI
    self._Window = tk.Tk()
    self._Window.wm_title("Image Captioning Demo")
    self._Window.config(background="#FFFFFF")
    self._Window.rowconfigure(0, weight=1)
    self._Window.columnconfigure(0, weight = 1)
    self._Window.minsize(480, 320)

    # Graphics window
    self._ImageFrame = tk.Frame(self._Window)
    self._ImageFrame.grid(row=0, column=0, columnspan=3, rowspan=2, padx=10, pady=10, sticky=tk.N+tk.S+tk.E+tk.W)
    self._ImageFrame.rowconfigure(0, weight=1)
    self._ImageFrame.columnconfigure(0, weight=1)

    # Capture video frames
    self._IsVideoRunnung = True
    self._VideoLabel = tk.Label(self._ImageFrame)
    self._VideoLabel.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
    self._VideoLabel.rowconfigure(0, weight=1)
    self._VideoLabel.columnconfigure(0, weight=1)
    self._showVideoFrame() 

    # Control Frame
    self._ControlFrame = tk.Frame(self._Window)
    self._ControlFrame.grid(row = 2, column=0, padx=10, pady=2, sticky=tk.N+tk.S)
    self._ControlFrame.rowconfigure(0, weight=0, minsize=30)
    self._ControlFrame.columnconfigure(0, weight=0)

    # Pause Button
    self._PauseButton = tk.Button(self._ControlFrame, text="Pause", command=self._pressPause)
    self._PauseButton.grid(row = 0, column = 0)
    self._Window.bind("<Key>", self._pressKey)

    # Captioning Button
    self._CaptionButton = tk.Button(self._ControlFrame, text="Caption", command=self._pressCaption)
    self._CaptionButton.grid(row = 0, column = 1)

    # Open Button
    self._OpenButton = tk.Button(self._ControlFrame, text="File...", command=self._openImage)
    self._OpenButton.grid(row = 0, column = 2)

    # Text Output
    self._TextFrame = tk.Frame(self._Window)
    self._TextFrame.grid(row = 3, column=0, padx=10, pady=2, sticky=tk.N+tk.S+tk.E+tk.W)
    self._TextFrame.rowconfigure(0, weight=1)
    self._TextFrame.columnconfigure(0, weight=1)
    ScrollBar = tk.Scrollbar(self._TextFrame)
    ScrollBar.grid(column=6, sticky=tk.W+tk.S+tk.N)
    self._OutputText = tk.Text(self._TextFrame, height=3, width=50)
    self._OutputText.grid(row=0, columnspan=5, column=0, sticky=tk.N+tk.S+tk.W+tk.E)
    self._OutputText.rowconfigure(0, weight=1)
    self._OutputText.columnconfigure(0, weight=1)
    ScrollBar.config(command=self._OutputText.yview)
    self._OutputText.config(yscrollcommand=ScrollBar.set)
    self._OutputText.delete('1.0', tk.END)
    self._OutputText.config(font=("Courier", 22))