Python:如何让我的gtk窗口移动缓慢

时间:2014-06-26 16:02:00

标签: python variables window pygtk

我希望我的gtk窗口从屏幕中间移动到屏幕左侧。不是一下子,而是慢慢地。这是我的代码:

#!/usr/bin/python
from termcolor import *
import os
import pygtk
import gtk
from qjfunctions import *
import time
pygtk.require('2.0')
SaveDir = "/home/marc/QuickJotTexts"

# main starts here    
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_position(gtk.WIN_POS_CENTER)
window.set_size_request(400, 400)
window.move(x,y)
window.set_title("QuickJot")

#####IMAGES#####
settings = gtk.Image()
settings.set_from_file("settings.png")
settings.show()
info = gtk.Image()
info.set_from_file("info.png")
info.show()

#####BUTTONS####
button1 = gtk.Button("Create A New Thought")
button1.connect("clicked", new_file)
button2 = gtk.Button("View A Thought")
button2.connect("clicked", view_file)
button3 = gtk.Button("Delete A Thought")
button3.connect("clicked", delete_file)
button4 = gtk.Button()
button4.add(settings)
button4.connect("clicked", setting_menu)
button5 = gtk.Button()
button5.add(info)
button5.connect("clicked", info_menu)

fixed = gtk.Fixed()
fixed.put(button1, 125, 140)
fixed.put(button2, 148, 175)
fixed.put(button3, 143, 210)
fixed.put(button4, 350, 10)
fixed.put(button5, 305, 10)

window.add(fixed)
window.show_all()

reminder()
gtk.main()

请注意它所说的行:

window.move(x,y)

是否会使窗口移动的代码行。 这可能需要一个循环,如下所示:

loop = 1
while loop == 1:
x = 100
y = 100
#here is where the x and y values will change, slowly moving the window like an animation
x = x-1
y = y-1
window.move(x,y)

我可能完全错了,可能有一种更简单的方法可以做到这一点。反馈将不胜感激。 谢谢StackOverflow:)

1 个答案:

答案 0 :(得分:0)

通过gobject.timeout_add(interval, callback, ...your.data...)使用重复超时并在那里进行“移动”。有关详细信息,请参阅pygtk2 tutorial


另请注意,pygtk2正在变老,新的做法是通过gintrospect使用内省绑定。

相关问题