使用Python tkinter GUI获取文本文件的打印预览

问题描述

搜索了所有互联网,找到了使用python tkinter打印硬拷贝的解决方案。我对tkinter打印机不是很了解,所以请帮助。该代码也属于我不认识的人:

将tkinter导入为tk 从线程导入线程 导入wx

def f_imprimir(值): #在这里您可以看到entry的值是作为字符串传递的,因此我们可以避免小部件出现任何问题 打印(值) 类TextDocPrintout(wx.Printout): def init (自己): wx.Printout。初始化((自己)

    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)
        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\n"
                          "Perhaps your current printer is not set correctly?\n\n"
                          "Printing Error",wx.OK)
            entry.config(state="normal")
        else:
            data = printer.GetPrintDialogData() 
            pdata = wx.PrintData(data.GetPrintData())  # force a copy
            entry.config(state="normal")

        printout.Destroy()
        self.Destroy()

app = wx.App(False)
PrintFrameworkSample().OnPrint()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)