【问题标题】:Python: How can I make my gtk window move slowlyPython:如何让我的 gtk 窗口缓慢移动
【发布时间】:2014-06-26 16:01:59
【问题描述】:

我希望我的 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:)

【问题讨论】:

    标签: python variables window pygtk


    【解决方案1】:

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


    还要注意 pygtk2 已经过时了,新的做事方式是通过 gintrospect 使用自省绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多