Python Forum
[Tkinter] How to print data to the printer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to print data to the printer
#1
Does anyone know how to make your program print data from my program to the printer?
Reply
#2
As an example you could use the following:
    printText = your_widget_namet.get("1.0", END)
    print(printText)
    filename = tempfile.mktemp(".txt")
    open(filename, "w").write(printText)
    # Bellow is call to print text from your_widget_name textbox
    win32api.ShellExecute(0,"printto", filename, '"%s"' % win32print.GetDefaultPrinter(), ".", 0)
"Often stumped... But never defeated."
Reply
#3
OK. I'll try thanks.
Reply
#4
That didn't work.
Reply
#5
Please show your complete code and any errors received in the appropriate tags so it can be analysed, that will make it easier to see what you have done and what might be your issue.
"Often stumped... But never defeated."
Reply
#6
I get the following error code: NameError: name 'tempfile' is not defined


printText =Label(root, text="hello")
print(printText)
filename = tempfile.mktemp(".txt")
open(filename, "w").write(printText)
# Bellow is call to print text from your_widget_name textbox
win32api.ShellExecute(0,"printto", filename, '"%s"' % win32print.GetDefaultPrinter(), ".", 0)
Reply
#7
Might be worth a look.
https://pypi.org/project/python-printer-escpos/
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#8
I'm getting closer but still not working. I went to that link and installed all components. But when I try running the following code, I get this error: ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it


printer = getNetworkPrinter()(host='192.168.0.1', port=8080)

printer.text("Hello World")
printer.lf()
Reply
#9
Are you going through a router? If so you may have to open a port to the printer.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#10
Yes the printer goes through a router.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there is a printer dialog box in PySimpleGUI shaunfish 2 1,582 Aug-22-2022, 07:29 PM
Last Post: deanhystad
  Problem with the printer function scratchmyhead 4 3,261 Oct-15-2020, 12:14 PM
Last Post: YvonneAlsop
  setup epson lq350 dot matrix printer by python-printer-escpos gray 10 8,853 Jun-05-2017, 01:20 PM
Last Post: sparkz_alot
  the rs232 printer is not working gray 10 8,579 May-17-2017, 09:21 AM
Last Post: gray

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020