2017-11-14 8 views
0

私のプログラムのコードが重くなり、私はそれを多くのファイルに分けたいと思います。python gtk pooは多くのファイルをプログラミングしていますか?

私は、そのコードここにある単一のチュートリアルが見つかりました:

#!/usr/bin/env python3 
# coding: utf-8 

#Box.py 
import gi 
gi.require_version('Gtk', '3.0') 
from gi.repository import Gtk, GdkPixbuf 

from BoxBoutton import BoxBoutton 

class MainWindow(Gtk.Window): 
    def __init__(self): 
     Gtk.Window.__init__(self) 

     box = Gtk.Box() 
     sublayout = BoxBoutton() 

     box.pack_start(sublayout, True, True, 0) 
     self.add(box) 

win = MainWindow() 
win.connect("delete-event", Gtk.main_quit) 
win.show_all() 
Gtk.main() 

秒:

#!/usr/bin/env python3 
# coding: utf-8 

#BoxBoutton.py 

import gi 
gi.require_version('Gtk', '3.0') 
from gi.repository import Gtk 

class BoxBoutton(Gtk.Grid): 
    def __init__(self): 
     Gtk.Grid.__init__(self) 

     btn = Gtk.Button(label="Mon super bouton") 
     self.attach(0, 0, 1, 1) 

を、私はこのエラーを持っている:

TypeError: Gtk.Grid.attach() takes exactly 6 arguments (5 given) 

はあなたのためにありがとうございましたヘルプ

+0

あなたはGtk.Gridの取り付け方法で子供を忘れてしまいました。問題を説明するために答えを編集しました。がんばろう。 –

+1

'delete-event'ではなく' destroy'イベントに 'Gtk.main_quit'を接続してください。これは、より意味的に正しいです。 – liberforce

答えて

1

あなた子供を忘れてattach method of Gtk.Grid

attach(child, left, top, width, height)

は、次のことを試してください。

self.attach(btn, 0, 0, 1, 1) 
関連する問題