Bottom Page

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?
Quote
#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."
Quote
#3
OK. I'll try thanks.
Quote
#4
That didn't work.
Quote
#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."
Quote
#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)
Quote
#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.
Gaming Collection
Homepage
Johnny's CookBook - Powered By: Python3.8 | Bootstrap4 | Apache2 | Django
Quote
#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()
Quote
#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.
Gaming Collection
Homepage
Johnny's CookBook - Powered By: Python3.8 | Bootstrap4 | Apache2 | Django
Quote
#10
Yes the printer goes through a router.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Problem with the printer function scratchmyhead 3 166 May-13-2020, 01:23 AM
Last Post: Larz60+
  setup epson lq350 dot matrix printer by python-printer-escpos gray 10 3,930 Jun-05-2017, 01:20 PM
Last Post: sparkz_alot
  the rs232 printer is not working gray 10 3,968 May-17-2017, 09:21 AM
Last Post: gray

Forum Jump:


Users browsing this thread: 1 Guest(s)