我需要帮助在 PYGTK 中选择和打印文本
我正在尝试制作一个如下所示的程序。
我该文件名为 Tux image.png 且我有另一个名为 File to use.txt 的文件,看起来像这样
Microsoft 苹果 惠普 戴尔 Linux Blackberry
我需要通过选择 Linux 一词并将其打印在图像下方,使程序看起来像上面的程序。这是我现在拥有的代码。
# two underscores
Class tux:
def __init__(self):
win = gtk.Window( )
img = gtk.Image( )
img.set_from_file(“Tux image.png”)
win.add(img)
win.show_all( )
win.connect(‘destroy’,gtk.main_quit)
tux( )
gtk.main( )
我只需要导入文档并在底部打印名称方面的帮助
I am trying to make a program that looks like the one below.
I that file is called Tux image.png and i have another called File to use.txt that looks like this
Microsoft
Apple
HP
Dell
Linux
Blackberry
I need to make the program appear like the one above by choosing the word Linux and printing it under the image.Here is the code that I have now.
# two underscores
Class tux:
def __init__(self):
win = gtk.Window( )
img = gtk.Image( )
img.set_from_file(“Tux image.png”)
win.add(img)
win.show_all( )
win.connect(‘destroy’,gtk.main_quit)
tux( )
gtk.main( )
I only need help with the importing of the document and printing the name at the bottom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您需要什么,但您可以像这样阅读 use.txt 文件:
'file_content' 现在应该包含:
您可以将它们拆分为列表:
之后您可以使用 gtk.ComboBox 来显示带有选项的组合框。
仍然不确定这是否是您想要的。
编辑:
添加组合和标签:
I'm not sure what you need, but you can read the use.txt file like this:
'file_content' should now contain:
You can split them in a list:
After that you could use gtk.ComboBox to display a combobox with choices.
Still not sure if this is what you want.
EDIT:
Adding a combo and a label:
您有 2 个选择:
1-将图像文件加载到Pixbuff中,在其上绘制文本,并将其显示在窗口中,这是较难的方法。
2- 在窗口中添加一个
gtk.Fixed
,并添加gtk.Image
(从文件加载)和gtk.Label
(包括text)到该gtk.Fixed
小部件,给定文本的特定位置(例如此处的 x=300,y=750)。像这样的东西:You have 2 options:
1- Load the image file into a Pixbuff, draw the text on it, and show it in the window, that is the hard way.
2- Add a
gtk.Fixed
into the window, and add bothgtk.Image
(loaded from file) andgtk.Label
(including the text) to thatgtk.Fixed
widget, given specific location for text (for example x=300, y=750 here). Something like this: