tkinter 窗口显示图片
时间: 2023-08-23 12:07:51 浏览: 106
A python Tkinter widget to display tile based maps
要在tkinter窗口中显示图片,你可以使用canvas.create_image方法将图片添加到画布上。首先,你需要导入tkinter模块,并创建一个窗口对象。然后,使用canvas.create_image方法将图片加载到画布上,并指定其位置和锚点。最后,使用canvas.pack方法将画布添加到窗口中。这样,图片就会显示在窗口上了。下面是一个示例代码:
```python
import tkinter as tk
window = tk.Tk()
window.title('显示图片')
canvas = tk.Canvas(window, width=800, height=600)
canvas.pack()
image_file = tk.PhotoImage(file='image.png')
image = canvas.create_image(400, 300, anchor='center', image=image_file)
window.mainloop()
```
注意,这里的"image.png"是你要显示的图片文件的路径。你可以根据需要修改窗口的大小和图片的位置。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [python Tk 一个窗口内加载两张或者多张图片](https://blog.csdn.net/lancerh/article/details/100122159)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [使用tkinter开发图形界面显示图片(Win10,Python)](https://blog.csdn.net/Alexabc3000/article/details/125026650)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Python Tkinter GUI(三)显示图片](https://blog.csdn.net/fjdmy001/article/details/78498150)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文