Hello everyone

I have created Tkinter application on Mac OS X.
I need to take printout for the output of that program from that application only.
Kindly please give me a valuable response.

Regards
BHANU

Recommended Answers

All 9 Replies

Member Avatar for leegeorg07

can you show us your code please

take printout for the output of that program

Do you mean save it in a file, send to the printer???

don't judge me because I'm a year 8!

My new sig: "Don't judge me because I'm a dumb-ass".

No no...
I have created a sample program using python Tkinter(An application)
which is not related to web application. Its Just a stand alone application.

Lets take an example
In our PC's, we have "OPEN OFFICE". There is an option for print.
Exactly, i need to get the print option for my application to take printout.
It won't be save in a file and send it to printer.

No no...
I have created a sample program using python Tkinter(An application)
which is not related to web application. Its Just a stand alone application.

Lets take an example
In our PC's, we have "OPEN OFFICE". There is an option for print.
Exactly, i need to get the print option for my application to take printout.
It won't be save in a file and send it to printer.

What is the output? Text, images, etc.?

It is easiest to use the print spooler "lpr" (on Linux but Mac is BSD based so there should be something similiar), otherwise you have to make sure that the data you want printed is formated properly for your particular printer, i.e. standard text, or a postscript or PDF file. Since your native language does not appear to be English, I am not sure what UTF characters are considered "standard text" in which languages and which printers, so using the print spooler converts where necessary to something the printer recognizes. To do this, you save whatever you want to a file, close the file and then use subprocess or os.system to call lpr + the file name. You can access/write to the printer driver directly. If you do not already know how to do that, then you don't want to try as you could easily overwrite the device file and then have to reboot before you can use the printer. Idle has a print to printer menu item and you could look at that code also. And a MAC OS-X forum would be the place to ask about lpr/print spoolers.

Member Avatar for leegeorg07

i asked a question like this and this is the code that i got for that (python25)

import tempfile
import win32api

def print_text(text):
	filename = tempfile.mktemp (" .txt")
	open (filename, "w").write (text)
	win32api.ShellExecute (
	0,
	"print",
	filename,
	None,
	".",
	0
	)
	

def print_file(file_path):
	filename = file_path
	open (filename, "r")
	win32api.ShellExecute (
	0,
	"print",
	filename,
	None,
	".",
	0
	)


def main():
	choice = float(raw_input("Press 1 to print text or 2 to print a file"))
	if choice == 1:
		text = raw_input("what is the text to print?")
		print_text(text)
	elif choice == 2:
		file_path = raw_input("what is the path to the file?")
		print_file(file_path)	
main()

While searching for the sample code,i found an example.


from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch

import cgi
import tempfile
import win32api

source_file_name = "c:/temp/temp.txt"
pdf_file_name = tempfile.mktemp (".pdf")

styles = getSampleStyleSheet ()
h1 = styles["h1"]
normal = styles["Normal"]

doc = SimpleDocTemplate (pdf_file_name)
#
# reportlab expects to see XML-compliant
# data; need to escape ampersands &c.
#
text = cgi.escape (open (source_file_name).read ()).splitlines ()

#
# Take the first line of the document as a
# header; the rest are treated as body text.
#
story = [Paragraph (text[0], h1)]
for line in text[1:]:
story.append (Paragraph (line, normal))
story.append (Spacer (1, 0.2 * inch))

doc.build (story)
win32api.ShellExecute (0, "print", pdf_file_name, None, ".", 0)


I installed report lab on mac os.
but it works on windows.
While executing, it shows

Traceback (most recent call last):
File "/Users/venkata/Desktop/prntsmp.py", line 7, in <module>
import win32api
ImportError: No module named win32api

Member Avatar for leegeorg07

yes its a module for windows but i dont think that you could use it for mac

I think you'd be better off finding out how native apps print on Mac OS X. I know Mac OS X uses CUPS, and I know it supposedly uses a server architecture, but that's about it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.