0

I'm making a tkinter based text widget and I'm trying to implement a new window function in it. But every time I click on the new window button I get this error in IDLE : RuntimeError: Calling Tcl from different appartment

Here's my code :

#!/usr/bin/env python
from Tkinter import *
from tkSimpleDialog import askstring
from tkFileDialog   import asksaveasfilename
from tkFileDialog import askopenfilename
from tkMessageBox import askokcancel
import Tkinter as tk
import ttk 
import threading
from ScrolledText import ScrolledText
Window = Tk() 
Window.title("TekstEDIT")

/..CODE.../

class newWindowThread(threading.Thread):
    def __init__(self, choosen=""):
        threading.Thread.__init__(self)
        self.choosen = choosen
    def run(self):
        if self.choosen == "":
            root = Tk()
            newEditor = SimpleEditor(root)
            root.mainloop()
        else:
            root = Tk()
            newEditor = SimpleEditor(root, self.choosen)
            root.mainloop()
/...CODE.../
wFile = Menu(menubar, tearoff=0,relief="raised")
    wFile.add_command(label="New", accelerator="Ctrl+N", command=self.onNew)
    wFile.add_command(label="New Window", accelerator="Ctrl+Shift+N", command=self.onNewWindow)
/...CODE.../
def onNewWindow(self):
    t=newWindowThread()
    t.start()

What's the source of the problem? How can I solve it?

Source Code: http://ideone.com/npWuYD

Thanks.

1 Answer 1

1

You can't mix Tkinter and threading in this way. Tkinter isn't thread-safe. Also, tkinter is designed such that you should only ever have a single instance of Tk running.

If you want multiple windows, you don't need threads and you don't need multiple instances of Tk. Create your root window as usual, and for other windows create an instance of Toplevel.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.