-1

I want to print some data from spreadsheet. I decided to use python. How can I call out a "Print preview"? For example like this:

screenshot

I tried something like this:

os.startfile('test.txt', 'print')

but it doesn't make a print preview.

I am using Python 3.9.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

3

Use this (tested on Windows 10):

import subprocess
subprocess.call(['notepad', '/p', "test.txt"])

On Linux use:

import os
os.system("lp text.txt")

As to previewing the file on screen, just use print function. If you want graphics use tkinter or any other graphics library (PyQt, etc)

Petr L.
  • 414
  • 5
  • 13