Tkinter的交互

import os

'''
path = "//172.28.61.13/cae_data/99.LY工作共享/999 临时文件/TO 张彩瑜/能量统计" #文件夹目录
filelist = os.listdir(path)  # 该文件夹下所有的文件(包括文件夹)
for file in filelist: #遍历文件夹
    print(file)
    old = path + '/' + file
    #new = old.split('_副本')[0]
    new = old.rsplit('.',1)[0] + '_副本.'+old.split('.')[-1]
    os.rename(old, new)


'''


import tkinter as tk
from tkinter import filedialog
def Select():
    Folderpath = filedialog.askdirectory()  # 获得选择好的文件夹
    if len(Folderpath) == 0:
        return
    entry_text.set(Folderpath)
def AddString():
    
    pass

win =tk.Tk()
# 设置主窗口
win.geometry('250x100')
#win.title("C语言中文网")
#win.iconbitmap('C:/Users/Administrator/Desktop/C语言中文网logo.ico')
win.resizable(0,0)
# 新建文本标签
labe1 = tk.Label(win, text="文件夹:")
labe2 = tk.Label(win, text="后缀名:")
# grid()控件布局管理器,以行、列的形式对控件进行布局,后续会做详细介绍
labe1.grid(row=0)
labe2.grid(row=1)
# 为上面的文本标签,创建两个输入框控件
entry_text = tk.StringVar()
entry1 = tk.Entry(win, textvariable=entry_text, font=('FangSong', 10))
entry2 = tk.Entry(win)
# 对控件进行布局管理,放在文本标签的后面

entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
tk.Button(win, text="选择", width=10, command=Select).grid(row=0, column=2, sticky="w", padx=10, pady=5)
tk.Button(win, text="增加后缀", width=10, command=AddString).grid(row=2, column=1, sticky="w", padx=10, pady=5)
# 显示主窗口
win.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供相关的代码。以下是一个简单的电子表程序,可以在Python中使用canvas和tkinter交互实现。 ```python import tkinter as tk import time class DigitalClock: def __init__(self, master): self.master = master self.mode = 'time' self.time_format = '%H:%M:%S' self.countdown_time = 60 self.canvas = tk.Canvas(master, width=200, height=100) self.canvas.pack() self.draw_clock() def draw_clock(self): self.canvas.delete('all') if self.mode == 'time': current_time = time.strftime(self.time_format) self.canvas.create_text(100, 50, text=current_time, font=('Helvetica', 30), tags='time') elif self.mode == 'countdown': self.canvas.create_text(100, 50, text=self.countdown_time, font=('Helvetica', 30), tags='countdown') def switch_mode(self): if self.mode == 'time': self.mode = 'countdown' else: self.mode = 'time' self.draw_clock() def start_countdown(self): self.mode = 'countdown' self.countdown_time = 60 self.do_countdown() def do_countdown(self): if self.countdown_time > 0: self.canvas.delete('countdown') self.canvas.create_text(100, 50, text=self.countdown_time, font=('Helvetica', 30), tags='countdown') self.countdown_time -= 1 self.master.after(1000, self.do_countdown) else: self.switch_mode() root = tk.Tk() clock = DigitalClock(root) button = tk.Button(root, text='Switch Mode', command=clock.switch_mode) button.pack() button2 = tk.Button(root, text='Start Countdown', command=clock.start_countdown) button2.pack() root.mainloop() ``` 在此代码中,我们创建了一个名为DigitalClock的类,该类包括了一个画布对象,用于在屏幕上显示时间或倒计时。我们还创建了两个按钮,一个用于切换模式,另一个用于启动倒计时。当切换模式时,我们会在时间模式和倒计时模式之间切换。在倒计时模式下,我们使用递归调用和after方法来实现倒计时的效果。 希望这可以帮助到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值