利用aardio写一个浏览图片的程序
时间: 2023-06-24 12:04:13 浏览: 95
以下是一个简单的利用 aardio 编写的浏览图片的程序:
```python
import os
import aardio
import ui
import image
class ImageViewer(ui.Form):
def __init__(self):
ui.Form.__init__(self)
self.Text = 'Image Viewer'
self.Width = 600
self.Height = 450
self.CenterScreen()
self.resizable = False
self.initComponents()
self.Show()
def initComponents(self):
self.lstFiles = ui.ListBox(self)
self.lstFiles.Width = 180
self.lstFiles.Height = 370
self.lstFiles.Top = 10
self.lstFiles.Left = 10
self.lstFiles.DoubleClick += self.lstFiles_DoubleClick
self.lstFiles.SelectedIndexChanged += self.lstFiles_SelectedIndexChanged
self.Controls.Add(self.lstFiles)
self.picPreview = ui.PictureBox(self)
self.picPreview.Top = 10
self.picPreview.Left = 200
self.picPreview.Width = 380
self.picPreview.Height = 380
self.picPreview.SizeMode = ui.PictureBoxSizeMode.Zoom
self.Controls.Add(self.picPreview)
self.btnOpen = ui.Button(self)
self.btnOpen.Text = 'Open'
self.btnOpen.Top = 390
self.btnOpen.Left = 10
self.btnOpen.Click += self.btnOpen_Click
self.Controls.Add(self.btnOpen)
self.btnClose = ui.Button(self)
self.btnClose.Text = 'Close'
self.btnClose.Top = 390
self.btnClose.Left = 90
self.btnClose.Click += self.btnClose_Click
self.Controls.Add(self.btnClose)
def lstFiles_DoubleClick(self, sender, e):
self.showImage()
def lstFiles_SelectedIndexChanged(self, sender, e):
self.showImage()
def btnOpen_Click(self, sender, e):
self.openFolder()
def btnClose_Click(self, sender, e):
self.Close()
def openFolder(self):
foldername = ui.FolderDialog.ShowDialog()
if foldername:
self.lstFiles.Items.Clear()
for file in os.listdir(foldername):
if file.endswith('.jpg') or file.endswith('.png'):
self.lstFiles.Items.Add(file)
def showImage(self):
if self.lstFiles.SelectedItem:
filename = os.path.join(ui.FolderDialog.SelectedPath, self.lstFiles.SelectedItem)
img = image.Image.FromFile(filename)
self.picPreview.Image = img
app = ImageViewer()
ui.Application.Run(app)
```
这个程序可以打开指定文件夹中的 JPG 和 PNG 格式的图片,并可以通过鼠标双击或选择列表中的图片来预览。同时,也支持关闭程序和打开其它文件夹。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)