简单的TK问题 - 当焦点不清晰时刷新画布 [英] Simple TK Question - refreshing the canvas when not in focus

查看:84
本文介绍了简单的TK问题 - 当焦点不清晰时刷新画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家!

我用Tk不太好,而且我用的是非常简单的画布

画一些照片(这与诺基亚有关)屏幕模拟器我几天前有一个

的帖子。)


无论如何,一切都很好,除了一件事。当我不在程序中时,

并且程序收到一个绘图命令(来自FIFO管道),画布

在我点击进入程序之前不会刷新。如何强制它刷新,或强制窗口获得焦点?看起来很漂亮

常见的行为,但我尝试过的一些东西都没用。


类屏幕():

def __init __(自我):

self.root = Tkinter.Tk()

self.root.title('''Nokia Canvas'')

self.canvas = Tkinter.Canvas(self.root,width = 130,

height = 130)

self.canvas.pack()

self.root.mainloop()


然后我做了很长的路线:

self.canvas.create_line(args [0],args [1],args [2],

args [3],填充=颜色)

self.canvas.pack()


我试过self.root.set_focus(),self.root.force_focus(),

self.canvas.update()等,但我可以不用了。

谢谢!

布莱恩

解决方案

周二,29日2008年4月15:22:12 +0200,blaine< fr ***** @ gmail.comwrote:


大家好!
$ b $我对T不太好k,我正在使用一个非常简单的画布

画一些图片(这与诺基亚屏幕模拟器有关,我几天前发了一张

帖子)。


无论如何,一切都很好,除了一件事。当我不在程序中时,

并且程序收到一个绘图命令(来自FIFO管道),画布

在我点击进入程序之前不会刷新。如何强制它刷新,或强制窗口获得焦点?看起来很漂亮

常见的行为,但我尝试过的一些东西都没用。


类屏幕():

def __init __(自我):

self.root = Tkinter.Tk()

self.root.title('''Nokia Canvas'')

self.canvas = Tkinter.Canvas(self.root,width = 130,

height = 130)

self.canvas.pack()

self.root.mainloop()


然后我做了很长的路线:

self.canvas.create_line(args [0],args [1],args [2],

args [3],fill = color)

self.canvas.pack()



无关的问题:为什么你在这里再次做一个.pack()?包装

小部件只需将其插入其容器中的正确位置,因此您只需要
一次。所以你在__init__中所做的就足够了。


我试过self.root.set_focus(),self.root.force_focus(),
self.canvas.update()等,但我无法得到它。



IIRC:

- self.root.set_focus()仅在您的应用已经具有
$ b $时才有效b焦点,所以这不是你需要的。

- self.root.force_focus()通常被认为是邪恶的:它会给

无论用户在做什么,都要专注于你的应用程序,这通常是* b $ b *真的很烦人。所以我猜很多窗口管理员只是拒绝做b / b
;这可能是这里发生的事情。


但是self.canvas.update()应该可以工作。如果它没有,那么你的平台上有可能限制它可以阻止它工作......你是否b $ b碰巧有其他应用程序可以更新他们的显示,而他们

没有焦点?他们有同样的问题吗?如果他们这样做,那么这可能是平台上的一个限制,我想你不可能做任何关于它的事情...... BTW,你在什么平台?


谢谢!

布莱恩



HTH

-

python -c" print''''。join([chr(154 - ord(c))for c in

''U(17zX(%,5.zmz5(17l8(%,5.Z *(93-965


l7 + - ''])"


4月29日上午10点36分,Eric Brunel< see.signat ... @ no.spamwrote:


On Tue,2008年4月29日15:22:12 +0200,blaine< frik ... @ gmail.comwrote:


嘿大家!

我对Tk不是很好,而且我使用的是一个非常简单的画布

画一些图片(这与诺基亚屏幕模拟器有关,我有一个
几天前发布的帖子)。


无论如何,一切都很好,除了一件事。当我不在程序中时,

并且程序收到一个绘图命令(来自FIFO管道),画布

在我点击进入程序之前不会刷新。如何强制它刷新,或强制窗口获得焦点?看起来很漂亮

常见的行为,但我尝试过的一些事情并没有奏效。


Class screen():

def __init __(self):

self.root = Tkinter.Tk()

self.root.title('''Nokia Canvas'')

self.canvas = Tkinter.Canvas(self.root,width = 130 ,

height = 130)

self.canvas.pack()

self.root.mainloop()


然后我做了很长的路线:

self.canvas.create_line(args [0],args [1],args [2] ,

args [3],fill = color)

self.canvas.pack()



不相关问题:为什么你在这里再做一个.pack()?包装

小部件只需将其插入其容器中的正确位置,因此您只需要
一次。所以你在__init__中所做的就足够了。


我试过self.root.set_focus(),self.root.force_focus(),
self.canvas.update()等,但我无法得到它。



IIRC:

- self.root.set_focus()仅在您的应用已经具有
$ b $时才有效b焦点,所以这不是你需要的。

- self.root.force_focus()通常被认为是邪恶的:它会给

无论用户在做什么,都要专注于你的应用程序,这通常是* b $ b *真的很烦人。所以我猜很多窗口管理员只是拒绝做b / b
;这可能是这里发生的事情。


但是self.canvas.update()应该可以工作。如果它没有,那么你的平台上有可能限制它可以阻止它工作......你是否b $ b碰巧有其他应用程序可以更新他们的显示,而他们

没有焦点?他们有同样的问题吗?如果他们这样做,那么这可能是平台上的一个限制,我想你不可能做任何关于它的事情...... BTW,你在哪个平台?


谢谢!

Blaine



HTH

-

python -c" print''''。join([chr(154 - ord(c))for c in

''U(17zX(%,5.zmz5(17l8(%,5.Z *(93-965)


Hey everyone!
I''m not very good with Tk, and I am using a very simple canvas to
draw some pictures (this relates to that nokia screen emulator I had a
post about a few days ago).

Anyway, all is well, except one thing. When I am not in the program,
and the program receives a draw command (from a FIFO pipe), the canvas
does not refresh until I click into the program. How do I force it to
refresh, or force the window to gain focus? It seems like pretty
common behavior, but a few things that I''ve tried have not worked.

Class screen():
def __init__(self):
self.root = Tkinter.Tk()
self.root.title(''Nokia Canvas'')
self.canvas = Tkinter.Canvas(self.root, width =130,
height=130)
self.canvas.pack()
self.root.mainloop()

Then somewhere a long the line I do:
self.canvas.create_line(args[0], args[1], args[2],
args[3], fill=color)
self.canvas.pack()

I''ve tried self.root.set_focus(), self.root.force_focus(),
self.canvas.update(), etc. but I can''t get it.
Thanks!
Blaine

解决方案

On Tue, 29 Apr 2008 15:22:12 +0200, blaine <fr*****@gmail.comwrote:

Hey everyone!
I''m not very good with Tk, and I am using a very simple canvas to
draw some pictures (this relates to that nokia screen emulator I had a
post about a few days ago).

Anyway, all is well, except one thing. When I am not in the program,
and the program receives a draw command (from a FIFO pipe), the canvas
does not refresh until I click into the program. How do I force it to
refresh, or force the window to gain focus? It seems like pretty
common behavior, but a few things that I''ve tried have not worked.

Class screen():
def __init__(self):
self.root = Tkinter.Tk()
self.root.title(''Nokia Canvas'')
self.canvas = Tkinter.Canvas(self.root, width =130,
height=130)
self.canvas.pack()
self.root.mainloop()

Then somewhere a long the line I do:
self.canvas.create_line(args[0], args[1], args[2],
args[3], fill=color)
self.canvas.pack()

Unrelated question: why are you doing a .pack() again here? Packing the
widget just inserts it at the right place in its container, so you only
have to do it once. So the one you did in __init__ is enough.

I''ve tried self.root.set_focus(), self.root.force_focus(),
self.canvas.update(), etc. but I can''t get it.

IIRC:
- self.root.set_focus() will only work if your application already has the
focus, so it''s not what you need here.
- self.root.force_focus() is usually considered as evil: it''ll give the
focus to your application whatever the user is doing, which is usually
*really* annoying. So I guess a lot of window managers just refuse to do
it; this may be what happens here.

But self.canvas.update() should work. If it doesn''t, then there are
probably limitations on your platform that prevents it to work... Do you
happen to have other applications that can update their display while they
don''t have the focus? Do they have the same problem? If they do, it''s
probably a limitation on the platform and I guess you won''t be able to do
anything about it... BTW, what platform are you on?

Thanks!
Blaine

HTH
--
python -c "print ''''.join([chr(154 - ord(c)) for c in
''U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965


l7+-''])"


On Apr 29, 10:36 am, "Eric Brunel" <see.signat...@no.spamwrote:

On Tue, 29 Apr 2008 15:22:12 +0200, blaine <frik...@gmail.comwrote:

Hey everyone!
I''m not very good with Tk, and I am using a very simple canvas to
draw some pictures (this relates to that nokia screen emulator I had a
post about a few days ago).

Anyway, all is well, except one thing. When I am not in the program,
and the program receives a draw command (from a FIFO pipe), the canvas
does not refresh until I click into the program. How do I force it to
refresh, or force the window to gain focus? It seems like pretty
common behavior, but a few things that I''ve tried have not worked.

Class screen():
def __init__(self):
self.root = Tkinter.Tk()
self.root.title(''Nokia Canvas'')
self.canvas = Tkinter.Canvas(self.root, width =130,
height=130)
self.canvas.pack()
self.root.mainloop()

Then somewhere a long the line I do:
self.canvas.create_line(args[0], args[1], args[2],
args[3], fill=color)
self.canvas.pack()


Unrelated question: why are you doing a .pack() again here? Packing the
widget just inserts it at the right place in its container, so you only
have to do it once. So the one you did in __init__ is enough.

I''ve tried self.root.set_focus(), self.root.force_focus(),
self.canvas.update(), etc. but I can''t get it.


IIRC:
- self.root.set_focus() will only work if your application already has the
focus, so it''s not what you need here.
- self.root.force_focus() is usually considered as evil: it''ll give the
focus to your application whatever the user is doing, which is usually
*really* annoying. So I guess a lot of window managers just refuse to do
it; this may be what happens here.

But self.canvas.update() should work. If it doesn''t, then there are
probably limitations on your platform that prevents it to work... Do you
happen to have other applications that can update their display while they
don''t have the focus? Do they have the same problem? If they do, it''s
probably a limitation on the platform and I guess you won''t be able to do
anything about it... BTW, what platform are you on?

Thanks!
Blaine


HTH
--
python -c "print ''''.join([chr(154 - ord(c)) for c in
''U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965


这篇关于简单的TK问题 - 当焦点不清晰时刷新画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆