Python Forum
Open parrallel problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open parrallel problem
#1
*** I Don't know why, I already tried to post this, but for some reason it seams that my post disappeared or was never posted (maybe I didn't press the right button). Anyway, if it got removed by a moderator because something was wrong, feel free to remove this one again, please just tell me what's wrong by PM. Thank you***

Hello,
I'm making a piece of software to control my printer by sending commands to it.
But now I got a big problem, which is that the printer wont do anything until I close the port.

Here is an example :
from tkinter import *

printer = open("/dev/lp0", "w")

win = Tk()
win.geometry("100x100")

def send(text):
    printer.write(str(text)) #Print text
    printer.write("\x0A\x0D") #Line feed and carriage return

textEntry = Entry(win)
textEntry.pack()

sendText = Button(win, text="Print", command=lambda:send(textEntry.get()))
sendText.pack()

win.mainloop()

printer.close()
When pressing any button, nothing happens until I close the window.
Any idea ?

Thank you in advance,
Clément.
Reply
#2
The printer is buffered, so try a printer.flush(). This doc says to follow it with os.fsync() https://python-reference.readthedocs.io/...flush.html which may or may not be necessary depending on your OS.
Reply
#3
Oh yes, thank you !! Smile
It works with :
from tkinter import *

printer = open("/dev/lp0", "w")

win = Tk()
win.geometry("100x100")

def send(text):
    printer.write(str(text)) #Print text
    printer.write("\x0A\x0D") #Line feed and carriage return
    printer.flush()

textEntry = Entry(win)
textEntry.pack()

sendText = Button(win, text="Print", command=lambda:send(textEntry.get()))
sendText.pack()

win.mainloop()

printer.close()
THANK YOU SO MUCH !
Reply


Forum Jump:

User Panel Messages

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