0

I make a GUI with Tkinter.And I set a button to open a txt file when I click it.When the default open mode of txt is sublime text2,the GUI works well.But when I change the default open mode of txt to windows notepad,the GUI will crash.And the GUI will work ubtil I close the txt file.

# -*- coding: utf-8 -*-
from Tkinter import *
import tkFont
import os

class System(object):
    """docstring for system"""
    def __init__(self):
        self.root = Tk()
        self.b1 = Button(self.root,text = 'open a ui.txt ',command = self.openfile)
        self.b1.pack()

        self.root.mainloop()
    def openfile(self):
        os.popen('ui.txt')

if __name__ == '__main__':
    System()

The chart below had crashed.

enter image description here

When I close txt file.It worked again.But sublime text2 is normal.So why?……How can I solve this situation?I want to make a exe,so most people want to open a txt file with notepad.

Peng He
  • 2,023
  • 5
  • 17
  • 24
  • [os.popen](https://docs.python.org/2/library/os.html#os.popen) doc: "This function is obsolete. Use the subprocess module." – furas Jan 07 '16 at 09:54
  • 1
    see: [Open document with default application in Python](http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python) – furas Jan 07 '16 at 09:56

0 Answers0