Created
April 20, 2026 17:44
-
-
Save dandrake/ecad24ec6ce9e91ff2409ff6f1269746 to your computer and use it in GitHub Desktop.
simplest way to display an image in a Python tkinter program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tkinter as tk | |
| def main(): | |
| win = tk.Tk() | |
| win.geometry("400x200") | |
| label = tk.Label(win, text="Here is an image.") | |
| label.grid(row=0, column=0) | |
| my_tk_photoimage = tk.PhotoImage(file="your_image_here.png") | |
| img_widget = tk.Label(win, image=my_tk_photoimage) | |
| img_widget.grid(row=1, column=0) | |
| win.mainloop() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment