鱼C论坛

 找回密码
 立即注册
查看: 2627|回复: 9

tkinter实现过程中发现create_text竟然没有textvariable

[复制链接]
发表于 2017-5-12 10:07:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
tkinter实现过程中发现create_text竟然没有textvariable功能,求助那如果我要在画布上显示可变的文本时要怎么办呢??
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-5-12 10:14:04 | 显示全部楼层
有搜到一个网页:python - How to add a Tkinter Text Variable in canvas text
http://stackoverflow.com/questio ... able-in-canvas-text


但是打不开啊,估计被墙了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-5-12 11:55:00 | 显示全部楼层

回帖奖励 +3 鱼币

豌图酱 发表于 2017-5-12 10:14
有搜到一个网页:python - How to add a Tkinter Text Variable in canvas text
http://stackoverflow.co ...

我这能打开阿
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-5-12 12:00:00 | 显示全部楼层
#Use a trace on the StringVar:

from tkinter import *

root = Tk()

s = StringVar(root, '23.1')
# your image here
image1 = PhotoImage(width=200, height=200)
image1.put('blue', to=(0,0,199,199))

canvas = Canvas(root, width=300, height=300)
canvas.pack()
canvas.create_image(150,150, anchor='c', image=image1)
txt = canvas.create_text(150,150, font='Helvetica 24 bold', text=s.get())

def on_change(varname, index, mode):
    canvas.itemconfigure(txt, text=root.getvar(varname))

s.trace_variable('w', on_change)

def trigger_change():
    s.set('26.0')

root.after(2000, trigger_change)
root.mainloop()
##Alternatively, you could just use a Label widget and take advantage of the compound option.

from tkinter import *

root = Tk()

s = StringVar(root, 'fine')
image1 = PhotoImage(width=200, height=200)
image1.put('blue', to=(0,0,199,199))
image2 = PhotoImage(width=200, height=200)
image2.put('gray70', to=(0,0,199,199))

lbl = Label(root, compound='center', textvariable=s, image=image1)
lbl.pack()

def trigger_change():
    lbl.config(image=image2)
    s.set('cloudy')

root.after(2000, trigger_change)
root.mainloop()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-5-12 15:37:13 | 显示全部楼层

那个trace_variable是什么意思,内置函数嘛~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-5-14 20:27:37 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-9-30 15:09:05 | 显示全部楼层

回帖奖励 +3 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-10-1 11:43:32 | 显示全部楼层

回帖奖励 +3 鱼币

666
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-12-20 10:08:15 | 显示全部楼层
来顶帖子得鱼币
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-24 16:27:51 | 显示全部楼层

回帖奖励 +3 鱼币

学习学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-8 00:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表