I am having a problem possibly due to my lack of knowledge. I want to open the windows dialog to choose printer and send to print (to a printer) using Tkinter.
Currently, I use a code to relate Tkinter to Wxpython and make it asynchronous creating a separate process.
This is the code mentioned above:
from tkinter import *
from threading import Thread
import wx
def f_imprimir(ventana, entry):
    class TextDocPrintout(wx.Printout):
        def __init__(self):
            wx.Printout.__init__(self)
        def OnPrintPage(self, page):
            dc = self.GetDC()
            ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()     
            ppiScreenX, ppiScreenY = self.GetPPIScreen()     
            logScale = float(ppiPrinterX)/float(ppiScreenX)
            pw, ph = self.GetPageSizePixels()
            dw, dh = dc.GetSize()     
            scale = logScale * float(dw)/float(pw)
            dc.SetUserScale(scale, scale)
            logUnitsMM = float(ppiPrinterX)/(logScale*25.4)
            ### Print code ###
            return True
    class PrintFrameworkSample(wx.Frame):        
        def OnPrint(self):
            pdata = wx.PrintData()
            pdata.SetPaperId(wx.PAPER_A4)
            pdata.SetOrientation(wx.LANDSCAPE)
            data = wx.PrintDialogData(pdata)
            printer = wx.Printer(data)
            printout = TextDocPrintout()
            useSetupDialog = True
            if not printer.Print(self, printout, useSetupDialog) and printer.GetLastError() == 
wx.PRINTER_ERROR:
                wx.MessageBox(
                    "There was a problem printing.\n"
                    "Perhaps your current printer is not set correctly?",
                    "Printing Error", wx.OK)
            else:
                data = printer.GetPrintDialogData() 
                pdata = wx.PrintData(data.GetPrintData()) # force a copy
            printout.Destroy()
            self.Destroy()
    app=wx.App(False)
    PrintFrameworkSample().OnPrint()
    entry.config(state="normal")
def process(ventana, entry):
    entry.config(state="disable")
    t = Thread(target=f_imprimir, args=(ventana,entry))
    t.start()
v = Tk()
entry = Entry(v)
entry.pack()
v.bind("a", lambda a:process(v,entry))
when wx.app finishes, which can happen when the Printer Selector closes, I plan to change the status of the entry to "normal". But it throws an error when changing the state of the entry to "normal", which I suppose is because the window and the order I send are in separate processes. The error would be:
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Python38-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\DANTE\Google Drive\JNAAB\DESARROLLO\pruebas\pedasito.py", line 65, in f_imprimir
    entry.config(state="normal")
  File "C:\Python38-32\lib\tkinter\__init__.py", line 1637, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Python38-32\lib\tkinter\__init__.py", line 1627, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
RuntimeError: main thread is not in main loop
Does anyone have a solution for this problem or an alternative way to create the print window without blocking the TCL window and being able to block the entry? If there is a way to do it or send to print using Tkinter and avoid this mess it would be even better. Thank you.
 
    