Tkinter developers को local system के अंदर files के साथ interact करने की अनुमति देता है। इस लेख में, हम देखेंगे कि Tkinter packages जैसे filedialog और win32api module का उपयोग करके file की hardcopy कैसे print करें।
इन packages को import करने के लिए, हमें पहले इन modules को अपने environment में install करना होगा। win32api install करने के लिए, हम pip install pywin32 का उपयोग करेंगे।
उदाहरण
# Import the required libraries
from tkinter import *
from tkinter import filedialog
import win32api
# Create an instance of tkinter frame or window
win = Tk()
win.title('Print Hard Copy')
win.geometry("700x400")
# Define function
def print_file():
file = filedialog.askopenfilename(initialdir="/", title="Select any file", filetypes=(("Text files", "*.txt"), ("all files", "*.*")))
if file:
# Print Hard copy using Printer
win32api.ShellExecute(0, "Choose a File", file, None, ".", 0)
# Create a button for printing event
button = Button(win, text="Choose a File to Print", command=print_file).pack(pady=20)
# Keep running the window or frame
win.mainloop()
आउटपुट
उपरोक्त code चलाने से निम्न output produce होगा:

यदि आप button पर क्लिक करते हैं, तो यह एक folder खोल देगा जहां से आप print करने के लिए file select कर सकते हैं।