python怎么改字体_python,tkinter_Tkinter Label 如何改变Label中的文字样式,例如给文字加删除线,python,tkinter - phpStudy...

Tkinter Label 如何改变Label中的文字样式,例如给文字加删除线

如题。未查到Tkinter下,促发条件后,是否能修改label中文字的样式

class Pomodoro_app(Tk):

def add_task(self):

global time

time = StringVar()

time.set("Start")

task_content = askstring(title = 'Add a Task', prompt = "Input a task")

task_label = Label(self, text = task_content, font = ("Arial, 12")).grid(column = 0, row = 3)

task_start_button = Button(self, textvariable = time, command = self.start_working).grid(column = 1, row = 3)

def createWidgets(self):

self.welcome_label = Label(self, text = "Welcome to the Challenge!", font = ("Arial, 12")).grid(column = 0, row = 0, columnspan = 2)

self.add_task_button = Button(self, text = "Add Task", width = 20, command = self.add_task).grid(column = 0 , columnspan = 2)

def __init__(self):

"""GUI Initiation"""

Tk.__init__(self)

self.createWidgets()

"""window Initiation"""

self.resizable(False, False)

x = (self.winfo_screenwidth() - self.winfo_reqwidth()) / 2

y = (self.winfo_screenheight() - self.winfo_reqheight()) / 2

self.geometry('250x400+%d+%d' % (x, y))

相关阅读:

less嵌套时怎样写更好

ThinkPHP 能不能多id查询

关于UITableView Cell点击 pushviewcontroller 传值的问题

js 中重写原型,不重定向原型中的 constructor 会有问题吗?

语句、表达式、表达式语句怎么区分?有点混淆。

有没有关于建数据库的思路的好书 求推荐!!

PHP安装imagick扩展问题:已经安装但是没有扩展中的任何方法?

请问采用拼音或简拼做模糊搜索应该怎么搞?

关于maven项目管理问题

flask文章列表页的分页导航该如果处理?

jquery的这个this.find(":not(:has(:first))")什么意思?

laravel5.1 最佳的权限管理方案是什么?自带的ACL吗?

一加天气这个toolbar的menu是怎么做到的?

javascript修改bootstrap弹出菜单

jsp中cookie的问题

移动端 history.go会不兼容?

scrapy的这个案例“下一页”用循环实现怎么写?

做游戏排名遇到的数字题

两道前端笔试题

mysql按照特定顺序搜索数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实时显示 Ubuntu 网络拓扑的端口流量数据,你可以使用Python的第三方库psutil来获取系统信息,然后使用Matplotlib库绘制实时折线图。具体步骤如下: 1.安装相关库 ``` sudo apt-get install python3-tk pip3 install psutil matplotlib ``` 2.导入相关库 ```python import psutil import matplotlib.pyplot as plt import numpy as np import time ``` 3.设置图形的样式 ```python # 创建画布和子图 fig, ax = plt.subplots() # 设置x轴和y轴的范围 ax.set_xlim(0, 10) ax.set_ylim(0, 1000000) # 设置x轴和y轴的标签 ax.set_xlabel('Time(s)') ax.set_ylabel('Bytes') # 设置图形的标题 ax.set_title('Real-time Line Chart of Network Traffic') # 创建两条空的线条对象,并设置样式 line1, = ax.plot([], [], 'o-', label='eth0', lw=2, markersize=8) line2, = ax.plot([], [], 'o-', label='eth1', lw=2, markersize=8) # 添图例 ax.legend() ``` 4.编写更新数据的函数 ```python def update_data(): # 获取eth0和eth1的流量数据 net_io_counters = psutil.net_io_counters(pernic=True) eth0 = net_io_counters['eth0'] eth1 = net_io_counters['eth1'] # 获取当前时间戳 current_time = time.time() # 更新线条的数据 line1.set_xdata(np.append(line1.get_xdata(), current_time)) line1.set_ydata(np.append(line1.get_ydata(), eth0.bytes_sent + eth0.bytes_recv)) line2.set_xdata(np.append(line2.get_xdata(), current_time)) line2.set_ydata(np.append(line2.get_ydata(), eth1.bytes_sent + eth1.bytes_recv)) # 如果数据点的数量大于100个,就删除前面的数据 if len(line1.get_xdata()) > 100: line1.set_xdata(line1.get_xdata()[1:]) line1.set_ydata(line1.get_ydata()[1:]) line2.set_xdata(line2.get_xdata()[1:]) line2.set_ydata(line2.get_ydata()[1:]) # 重新计算x轴和y轴的范围 ax.relim() ax.autoscale_view() # 重新绘制图形 fig.canvas.draw() # 延时一段时间,再次更新数据 fig.canvas.flush_events() fig.canvas.start_event_loop(0.01) ``` 5.循环调用更新数据的函数 ```python while True: update_data() ``` 这样就可以实时显示Ubuntu网络拓扑的端口流量数据了。注意,你需要根据实际情况修代码的网卡名称。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值