首页 新闻 搜索 专区 学院

如何修改python时钟(label)字体

0
悬赏园豆:50 [待解决问题]

import tkinter
import threading
import datetime
import time
app=tkinter.Tk()
app.overrideredirect(True)
app.attributes('-alpha',0.9)
app.attributes('-topmost',1)

app.geometry('200x100+100+100')
labelDateTime=tkinter.Label(app)
labelDateTime.pack(fill=tkinter.BOTH,expand=tkinter.YES)
labelDateTime.configure(bg='red')
labelDateTime.font=('黑体',46)
X=tkinter.IntVar(value=0)
Y=tkinter.IntVar(value=0)
canMove=tkinter.IntVar(value=0)
still=tkinter.IntVar(value=1)

def onLeftButtonDown(event):
app.attributes('-alpha',0.4)
X.set(event.x)
Y.set(event.y)
canMove.set(1)
labelDateTime.bind('<Button-1>',onLeftButtonDown)

def onLeftButtonUp(event):
app.attributes('-alpha',0.9)
canMove.set(0)
labelDateTime.bind('<ButtonRelease-1>',onLeftButtonUp)

def onLeftButtonMove(event):
if canMove.get()==0:
return
newX=app.winfo_x()+(event.x-X.get())
newY=app.winfo_y()+(event.y-Y.get())
g='110x25+'+str(newX)+'+'+str(newY)
app.geometry(g)
labelDateTime.bind('<B1-Motion>',onLeftButtonMove)

def onRightButtonDown(event):
still.set(0)
t.join(0.2)
app.destroy()
labelDateTime.bind('<Button-3>',onRightButtonDown)

def nowDateTime():
while still.get()==1:
now=datetime.datetime.now()
s=str(now.year)+'-'+str(now.month)+':'+str(now.day)+' '
s=s+str(now.hour)+':'+str(now.minute)+':'+str(now.second)
labelDateTime['text']=s
labelDateTime.font=('黑体',46)
time.sleep (0.2)
t=threading.Thread(target=nowDateTime)
t.daemon=True
t.start()

app.mainloop()

段昱辰的主页 段昱辰 | 初学一级 | 园豆:68
提问于:2021-02-20 16:51
< >
分享
所有回答(2)
-1
code 
      格式化

查一下markdown的代码块怎么写

寻觅beyond | 园豆:863 (小虾三级) | 2021-02-20 17:45

?????求大神指点

支持(0) 反对(0) 段昱辰 | 园豆:68 (初学一级) | 2021-02-20 18:20
0

import pygame
import tkinter
import threading
import datetime
import time
app=tkinter.Tk()
app.overrideredirect(True)
app.attributes('-alpha',0.9)
app.attributes('-topmost',1)

app.geometry('200x100+500+350')
labelDateTime=tkinter.Label(app)
labelDateTime.pack(fill=tkinter.BOTH,expand=tkinter.YES)
labelDateTime.configure(bg='red')
labelDateTime.font=(
36)
X=tkinter.IntVar(value=0)
Y=tkinter.IntVar(value=0)
canMove=tkinter.IntVar(value=0)
still=tkinter.IntVar(value=1)

def onLeftButtonDown(event):
app.attributes('-alpha',0.4)
X.set(event.x)
Y.set(event.y)
canMove.set(1)
labelDateTime.bind('<Button-1>',onLeftButtonDown)

def onLeftButtonUp(event):
app.attributes('-alpha',0.9)
canMove.set(0)
labelDateTime.bind('<ButtonRelease-1>',onLeftButtonUp)

def onLeftButtonMove(event):
if canMove.get()==0:
return
newX=app.winfo_x()+(event.x-X.get())
newY=app.winfo_y()+(event.y-Y.get())
g='110x25+'+str(newX)+'+'+str(newY)
app.geometry(g)
labelDateTime.bind('<B1-Motion>',onLeftButtonMove)

def onRightButtonDown(event):
still.set(0)
t.join(0.2)
app.destroy()
labelDateTime.bind('<Button-3>',onRightButtonDown)

def nowDateTime():
while still.get()==1:
now=datetime.datetime.now()
s=str(now.year)+'-'+str(now.month)+':'+str(now.day)+' '
s=s+str(now.hour)+':'+str(now.minute)+':'+str(now.second)
labelDateTime['text']=s
labelDateTime.font=('黑体',46)
time.sleep (0.2)
t=threading.Thread(target=nowDateTime)
t.daemon=True
t.start()

app.mainloop()

段昱辰 | 园豆:68 (初学一级) | 2021-02-25 17:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册