python tkinter 制作九宫格

import tkinter as tk
import tkinter.messagebox as msgbox
from tkinter.filedialog import askopenfilename
from image_slicer import slice


class Application(tk.Tk):
    def __init__(self):
        super().__init__()
        
        self.img_path = tk.StringVar()
        self.init_ui()
        
        
    def init_ui(self):
        self.title("制作九宫格")
        self.geometry("300x100")
        self.iconbitmap("favicon.ico")

        self.root = tk.Frame(self)
        
        self.lbl_path = tk.Label(self.root, text="图片:")
        self.lbl_path.grid(row=0, column=0)
        
        self.txt_path = tk.Entry(self.root, width=21, textvariable=self.img_path)
        self.txt_path.grid(row=0, column=1, padx=5, pady=5, sticky=tk.W)
        
        self.btn_sel = tk.Button(self.root, text="选择文件", command=self.sel_img_file)
        self.btn_sel.grid(row=0, column=2, padx=5, pady=5, sticky=tk.W)
        
        self.lbl_tiles = tk.Label(self.root, text="数量:")
        self.lbl_tiles.grid(row=1, column=0)
        
        self.spn_tiles = tk.Spinbox(self.root, values=(4, 6, 9))
        self.spn_tiles.grid(row=1, column=1, padx=5, pady=5, sticky=tk.W)
        
        self.btn_slice = tk.Button(self.root, text="切割图片", command=self.slice_img)
        self.btn_slice.grid(row=1, column=2, padx=5, pady=5, sticky=tk.W)

        self.root.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
        
    def sel_img_file(self):
        img_file = askopenfilename(title="选择图片", initialdir=".", filetypes=(('JPG 图片', '*.jpg'), ('PNG 图片', '*.png'), ('所有文件', '*.*')))
        self.img_path.set(img_file)
        
    def slice_img(self):
        if self.img_path:
            slice(self.img_path.get(), int(self.spn_tiles.get()))


if __name__ == "__main__":
    app = Application()
    app.mainloop()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值