I-PyGTK 3: okokufundisa okuncane kwe-GUI ngePython + GTK + 3

Sizokwenza uhlelo oluncane ngePyGTK 3.0 nayo esebenzela iPyGTK 3.4. Le GUI encane izokufundisa ukuthi ungahlukanisa kanjani uhlelo lube ngamafayela amabili noma ngaphezulu.

Ungavakashela okokufundisa kukaSebastian Pölsterl ku-PyGTK 3 entsha, nansi isifundo esisha, ngishiya isixhumanisi:

http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html

Le yibhulogi kaSebastian.

http://k-d-w.org/node/88

Ukugxekwa kwalesi sifundo nguSebastian ukuthi akufundisi ukwahlukanisa uhlelo lube izingxenye noma amafayili amaningi, bekungaba kuhle uma ekhombisa isibonelo sendlela yokwenza nePyGTK 3.

Zonke izinhlelo ezinkulu nezinkimbinkimbi zihlukaniswe ngamafayela amaningi futhi amafayela abekwa nakwamanye umkhombandlela, okungukuthi, atholakala kumafolda ahlukile.

Ake siqale ngesibonelo esincane:

Nayi ikhodi yokubhala efayeleni elilodwa elibizwa nge-gui.py. Sivula isihleli sombhalo weGedit noma isihleli esisisebenzisa kakhulu, sikopisha ikhodi engezansi bese siyigcina njenge-gui.py

kusuka gi.repository import Gtk class gui (): def on_open_clicked (self, button): phrinta "\" Open \ "button was clicked" def on_close_clicked (self, button): phrinta "Isicelo sokuvala" Gtk.main_quit () def __init__ (self): self.window = Gtk.Window () self.window.connect ('Dele-event', Gtk.main_quit) self.box = Gtk.Box () self.window.add (self.box) uqobo. inkinobho = Gtk.Button (label = 'Open') self.button.connect ("chofoza", self.on_open_clicked) self.box.pack_start (self.button, True, True, 0) self.button = Gtk.Button ( ilebula = 'Vala') self.button.connect ("uchofoze", self.on_close_click) self.box.pack_start (self.button, True, True, 0) self.window.show_all () Gtk.main () uma __name__ == '__main__': gui = gui ()

i-fronton

def on_open_clicked (self, button): phrinta "\" Vula \ "inkinobho ichofoziwe"

Kungumsebenzi owenziwe wasebenza esigungwini lapho sichofoza inkinobho evulekile. Isiginali yokuyenza isebenze yile:

self.button.connect ("kuchofoziwe", self.on_open_clicked) def on_close_clicked (self, button): phrinta "Isicelo sokuvala" Gtk.main_quit ()

Kungumsebenzi ocushiwe lapho sichofoza inkinobho yokuvala.

vala uhlelo esilusebenzisayo.

isignali yokuyisebenzisa

self.button.connect ("kuchofoziwe", self.on_close_clicked) kusuka ku- gi.repository import Gtk ### sincenga imitapo yolwazi yePyGTK ### class gui (): # # # incazelo yeklasi ebizwa ngokuthi i-gui isigaba esikhulu # ##

Isimemezelo samawijethi: amawijethi wuhlelo olunqunywe ngaphambili yimitapo yolwazi ebonakalayo esisebenzisayo. Isibonelo, amawijethi ayinkinobho, iwindi, ibhokisi, njll. Lawa amawijethi esiwamemezela ohlelweni lwethu.

self.window = Gtk.Window () ### iwindi ### self.box = Gtk.Box () ### ibhokisi #### self.button = Gtk.Button (label = 'Open') ### # inkinobho evulekile #### self.button = Gtk.Button (label = 'Close') #### inkinobho yokuvala #### self.window.add (self.box) #### ibhokisi liqukethwe iwindi elibizwa ngewindi #### self.box.pack_start (self.button, True, True, 0) ##### inkinobho iqukethe ebhokisini elibizwa ngebhokisi ### self.window.show_all () ## # sikhombisa lonke iwindi ### gui = gui () ### yakha into ye-gui ####

Sifaka uhlelo lwethu kufolda ebizwa ngokuthi elula kithi kwideskithophu

i-fert

Sivula ifolda nge-terminal, kimi ngisebenzisa i-Nemo kusuka ku-Linux Mint 14.

ivaliwe

Ukuhlanganisa sibeka ukuphela python gui.py

bona isithombe.

Isikhumulo

Manje sesiyabona uhlelo lwethu oluncane noma iwijethi entsha eyenziwe ngemitapo yolwazi yePyGTK 3

Kuyinto iwindi elula enezinkinobho ezimbili.

 

Untitled

 

Manje sehlukanisa uhlelo lube izingxenye ezintathu, bese ngishiya ikhodi yamafayela amathathu.

Ifayela lokuqala le-gui.py

kusuka gi.repository import Gtk from destroy import destroy from io import io class gui (destroy, io): def __init __ (self): self.window = Gtk.Window () self.window.connect ('delete-event', Gtk .main_quit) self.box = Gtk.Box () self.window.add (self.box) self.button = Gtk.Button (label = 'Open') self.button.connect ("chofoza", self.on_open_clicked ) self.box.pack_start (self.button, True, True, 0) self.button = Gtk.Button (label = 'Close') self.button.connect ("chofoza", self.on_close_clicked) self.box.pack_start (self.button, True, True, 0) self.window.show_all () Gtk.main () uma __name__ == '__main__': gui = gui ()

Ifayela lesibili io.py

isigaba io: def on_open_clicked (self, button): phrinta "\" Open \ "inkinobho ichofoziwe"

Ifayela lesithathu destroy.py

kusuka ku- gi.repository import Gtk class destroy: def on_close_clicked (self, button): phrinta "Closing application" Gtk.main_quit ()

Sifaka amafayela amathathu kufolda efanayo kithi, ifolda ibizwa ngokuthi ihlukaniswe kalula.

elula

Ukuhlanganisa amafayela amathathu. Sivula ifolda nge-terminal bese simane siyibuyisela ku-terminal

python gui.py

Ukulungiswa okwenziwe kukhodi ye-gui.py

kusuka ekubhubhiseni ukungenisa ukubhubhisa isitatimende se- ### ukungenisa ifayela lethu destroy.py ### kusuka ku-io import io ### isitatimende sokungenisa ifayela lethu io.py ### class gui (destroy, io): #### ekilasini main sifaka iziqeshana ezingaphansi ezibhubhisayo ne-io ####

Uyabona ukuthi umusho

def on_open_clicked (self, button): phrinta "\" Vula \ "inkinobho ichofoziwe"

Ayikho ku-gui.py, isefayilini io.py

Isigwebo

def on_close_clicked (uqobo, inkinobho):

phrinta "Uhlelo lokuvala"
I-Gtk.main_quit ()

itholakala kufayela le-destroy.py

Ngakho-ke singahlukanisa uhlelo lube ngamafayela amaningi atholakala kwizikhombisi ezahlukahlukene ngasikhathi sinye.

Ngakolunye uhlangothi, iPython iyinsika yesoftware yamahhala, futhi ishintshelwa ukusebenza ne-GTK 3.6 /3.8, igama layo iPyGTK. Ukulungiswa kwePython kwe-KDE kubizwa ngePyQT.

IPython iguqulelwe iMac OS neWINDOWS.

Ngiyethemba ukuthi lesi sifundo esincane sePyGTK3 sibe wusizo kuwe. Bangenza konke ukugxeka okwakhayo abakufunayo.

Ngiyazi futhi ngeGtk 3.4 /3.6 neVala GTK 3.4 / 3.6.

http://www.youtube.com/watch?v=9ckRn_sx8CE

Okokugcina, abasebenzisi be-KDE bayaxolisa ngokungasenzi isifundo esincane se-KDE.


Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Amazwana ayi-33, shiya okwakho

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.

  1.   Rots87 kusho

    Ku-kde ngincamela ukusebenzisa i-kdevelop (ngicabanga ukuthi yilokho okubizwa ngakho) ukudala i-gui ngokukhululeka kepha kusenzima ukuthola izinqubo zokwenza kwenzeke x into: '(

  2.   Ngobese kusho

    Kuhle kulabo bethu abasebenzisa iPython: D!

    Ukubingelela!

  3.   Pablo kusho

    Sawubona, kade ngangilandela lo mphakathi futhi anginasiqiniseko sokuthi ngabe ngiyaqala ukuphawula noma ngabe sengikwenzile ngaphambili 😀 (anginikwanga ukubhala imibono kuwebhu ngempela). Into ukuthi ngikwenzela ukushiya isiphakamiso ku-Elav no-KZKG ^ uGaara njengabaphathi, futhi ngicabanga ukuthi kungaba ngumqondo omuhle ukufaka i-plugin yombala we-syntax manje njengoba muva nje ngibona okuthunyelwe okuningi kunekhodi ngezilimi ezahlukahlukene zokuhlela. Ngiyazi ukuthi kunama-plugins ambalwa kepha angikazami noma yini njengoba ngingeyena umsebenzisi we-wordpress, ngakho-ke ngikushiya ucabange ngokusebenza kwesicelo. Ngithatha leli thuba ukubuza abanye abafundi ukuthi bacabangani ngalo mbono, ngoba ngiyazi ukuthi kukhona abantu laphaya abathanda ukufunda ikhodi ngaphandle kokuhlobisa. Ngiyaxolisa uma ngabe lokhu sekuvele kuphawulwe ngakho lapha futhi kwaliwa ngenxa yesizathu esithile, ngoba angikhumbuli ngibona izingxoxo ngale ndaba.

    1.    nxumabiyela kusho

      Iqiniso ukuthi ngithanda ukuthola ithuba lokufaka umbala ku-syntax ukugqamisa ikhodi yezilimi ezihlelayo.
      Lokho kungasiza abasebenzisi abafuna ukufunda izilimi ezihlelayo.

      Kepha, ngiyakhululeka nasithangamini nokuthi singaxoxa futhi sifunde ndawonye.

      1.    eliotime3000 kusho

        I-GNU Emacs inethezeke kakhudlwana, ngoba okungenani kufanele ukhethe ukuthi isiphi isihloli solimi lohlelo ofuna ukulusebenza (uma ungafuni isisindo esengeziwe seprosesa yakho, sebenzisa i-GNU Nano futhi ujabulele ubuncane bokusebenza).

        1.    nxumabiyela kusho

          U-Elio sikhuluma ngeWorpress. Kusetshenziswe kubhulogi Kusuka ku-Linux. Ayinayo imisebenzi yokufaka imibala ezinhlokweni zokuthunyelwe.

          1.    eliotime3000 kusho

            Oh ngiyaxolisa.

        2.    pvv92 kusho

          AmaNaaa emacs anethezekile kulabo abaneminwe engu-84 XD .., abantu abajwayelekile, ababhalela imiyalezo, i-sublimetext noma incwajana ++ xd

          1.    eliotime3000 kusho

            Into engaqondakali ukungafundi ukuthayipha, okudingeka ukuthi ikwazi ukuphatha i-GNU Emacs nezinqamuleli zayo zekhibhodi kahle. Ngaphezu kwalokho, i-GUI yayo yenza kube lula kuwe ukusebenzisa amamenyu ayo (ingasetshenziswa ku-Windows, kepha akunconywa ukukwenza ngemodi ejwayelekile kepha ngemodi ye-Prompt mode ukuze i-win32 ingadubuli iskripthi sakho).

  4.   UCarper kusho

    Isifundo esihle kakhulu. Kepha ngendlela, ikhodi yomthombo python ayihlanganisiwe, ulimi oluhunyushiwe.

    1.    I-Giskard kusho

      Ingafakwa kukhodi mbumbulu. Akusilo ulimi lomshini kepha ama-byte amele okuthile kutolika, kepha inqubo ibizwa nangokuthi ihlanganisiwe. Ngalo mqondo, kungenzeka ukusho ukuthi okuthile kuhlanganisiwe.

  5.   hty kusho

    Mhlawumbe kungcono ukufunda i-pytgk2 ngoba inguqulo yakamuva etholakalayo ye-Windows ingu-2.24. Uchungechunge 3 lubonakala ngokungabikho kwalo. Futhi izilimi ezimbi zithi i-gnome iphula wonke ama-apis enguqulweni ngayinye entsha.

    1.    nxumabiyela kusho

      Ngihlela ukuhlanganiswa ne-GTK 3.4 / 3.6 futhi iqiniso ukuthi baphula ukubekezela nekhanda lakho, kufanele uphinde ubhale ikhodi, manje ngiyaqonda ukuthi kungani abantu beLinux Mint bekhononda ngeGTK nangephrojekthi ye-GNOME.
      Kulabo be-MINT ngivumelana ne-GTK 2.4 lokhu akwenzekanga.

  6.   Carlos kusho

    Isifundo esihle nezinkomba.
    Imininingwane nje, njengoba ikhodi isifakiwe, kuma-indentations we-Python ayimpoqo futhi kufanele ahlonishwe kukhodi eyisibonelo.

    Ukubingelela!

    1.    nxumabiyela kusho

      Ngabe ungachaza ukuthi ukukhonjwa okuyimpoqo ku-Python kuqukethe ini? Ukukutshela iqiniso, angikaze ngikuzwe lokho. Ngizijwayele kabi izinkundla zePyGTK 2/3 ngesiNgisi futhi mhlawumbe ngiyakushaya indiva.

      1.    I-Giskard kusho

        KuPython awusebenzisi okhiye njengaku-C noma kumabhulokhi okuqala / wokugcina njengasePascal, kepha konke kuyaqondakala ngokuqondiswa okunikeza ikhodi. Lokho okungukuthi, amabhlogo abonwa njengalapho efakwe ngaphakathi. Kuyisici engisithanda ngokukhethekile. Ugwema ukubhala okhiye nezinto ezinjalo.

        1.    pvv92 kusho

          Angikuthandi nje lokho, kubonakala kulula ukubeka okhiye ababili abancane noma i-std :: endl;, kunokubonwa uma umugqa we-xd uhlelwe kahle

          1.    felipe kusho

            : p Uthisha wakho wezinhlelo uzokufakela u-0. Noma okubi kakhulu bazokuxosha emsebenzini wakho. Okubaluleke kakhulu ukuthi ikhodi ifundeka nakho konke lokho okushoyo

          2.    pvv92 kusho

            ngigcina ngabakhi bokuvala ubhande, kungenza ngifundeke kalula nge-XD ..

          3.    I-Giskard kusho

            Ngokuzimisela ???


            int main(int argc, char *argv[]){program_name = argv[0];while ((argc > 1) && (argv[1][0] == '-')) {switch (argv[1][1]) {case 'v':verbose = 1; break;case 'o':out_file = &argv[1][2];break;case 'l':line_max = atoi(&argv[1][2]);break;default:fprintf(stderr,"Bad option %s\n", argv[1]);usage();}++argv;--argc;} if (argc == 1) {do_file("print.in");} else {while (argc > 1) {do_file(argv[1]);++argv;--argc;}}return (0);}

            Uyabona? Ngaphandle kokungeniswa akuqondakali kahle. Futhi lokho kulula. Ngenye eyinkimbinkimbi, ngumhlanganisi kuphela oyiqondayo. Into ukuthi, njengoba KUFANELE uhlehlise noma kunjalo (ukuze abantu baqonde ikhodi) kungani kuzodingeka ungafuneki futhi usebenzise abahlukanisi? Kwanele ngokufakwa ngaphakathi futhi yilokho kuphela.

          4.    pvv92 kusho

            Vele, akukho okuqondakalayo, ngoba awuyihloniphi imithetho yokubhala okuhle kohlelo ku-c / c ++. Lokho okwenzile kuvumelekile kunoma yini, njengokufaka umsebenzi wokufaka isidleke, ngaphakathi komsebenzi ngaphakathi komunye umsebenzi ongaphakathi komunye, khona-ke ngifuna ukukubona xd uma ukwazi ukukuqonda.

          5.    pvv92 kusho

            ngendlela, ngokubukeka okubili, leyo khodi iqondakala kalula nge-xD

          6.    I-Giskard kusho

            Engikwenzile ngikwenze ngenhloso ukukubonisa ukuthi ngaphandle kokuqondiswa, yize kuhlanganiswa, kunzima kakhulu ukuqonda noma iyiphi ikhodi. Ngakho-ke unemithetho emi-2: I-indent futhi ihlanganisa ama-delimiters. Kepha lokho akusafuneki. KuPython ikhodi enjalo ayemukelwa ngutolika. Futhi unomthetho owodwa kuphela: Indent. Kulula.
            Kepha hheyi, wonke umuntu ngokuthanda kwakhe.

          7.    I-Atheyus kusho

            Zombili zilungile, zihlehlisiwe futhi azifakwanga ngaphakathi, ngombono wami ngithanda isitayela semicolon noma se-ruby, esifana ne-python kepha ukuhlehlisa akudingekile.

            Lokhu kuqondakala kangcono: P:

            i-echo 'int main (int argc, char * argv []) {program_name = argv [0]; ngenkathi ((argc> 1) && (argv [1] [0] ==' - ')) {switch (argv [ 1] [1]) {case 'v': verbose = 1; break; case 'o': out_file = & argv [1] [2]; break; icala 'l': line_max = atoi (& argv [1] [2]); break; default: fprintf (stderr, »Inketho embi % s \ n », argv [1]); ukusetshenziswa ();} ++ argv; –argc;} uma (argc == 1) {do_file (" print.in ");} okunye {ngenkathi (argc> 1 ) {do_file (argv [1]); ++ argv; –argc;}} buyisela (0);} '| i-perl -p -e 's / \ {/ \ {\ n \ t / g; s / \; / \; \ n \ t / g; s / \ t \} / \} / g;'

            Sanibonani

      2.    I-Giskard kusho

        Ngicabanga ukuthi uCarlos usho ukuthi lapho kuphuma khona ikhodi azikho ama-indents. Lokho ngekhophi nokunamathisela nje ngeke kusebenze. Angazi noma umaki ukhona yini lapho kwenziwa okuthunyelwe ukufaka ikhodi yolimi. Kungakuhle uma beyibeka uma ingekho.

        1.    I-Giskard kusho

          Ngivele ngabona ukuthi yini inkinga: i-CODE Tag isusa zonke izikhala namathebhu (akufanele ikwenze lokho !!!) Kepha uma ufaka i-nbsp kuyo ikhodi ibukeka ilungile. I-A0 ku-hex (160 ngo-dec) yize ngicabanga ukuthi kungahle kuncike kufonti (angazi). Uma isetshenziswa lapho iphuma kanjena:

          def fib(n):
              a, b = 0, 1
              while a < n:
                  print(a)
                  a, b = b, a+b

          Ukuthi ezivivinyweni zami kubukeka kukuhle, kepha anginakho ukubuka kuqala lapho ngibhala izimpendulo (futhi kufanele kube khona lokho !!!) Uma kungaphumi, akuyona iphutha lami

          1.    nxumabiyela kusho

            Bheka izibonelo ezinikezwa nguSebastian Pölsterl esifundweni sakhe sePyGTK 3, uSebastian akabeki amalebula.

            Isibonelo:

            http://python-gtk-3-tutorial.readthedocs.org/en/latest/entry.html#example

            ungabona konke okokufundisa kukaSebastian.

          2.    I-Giskard kusho

            Angazi ukuthi usho ukuthini. Engikushoyo ukuthi lapha, kokuthunyelwe, akunakwenzeka ukusebenzisa i-HTML Tag «CODE» ukuze lokho okubeka njengekhodi futhi kuphume kahle ku-indenti. Ekhasini olikhomba kulo, uma ubheka imithombo yekhasi, uzobona ukuthi ayisebenzisi i-CODE kepha isebenzisa amanye ama-delimiters e-HTML.
            Akuphikisana nekhodi oyifakile kepha kunalokho ukhomba iphutha ohlelweni lokuthumela lwaleli sayithi. Yikuphi, mhlawumbe, abalawuli abangakulungisa.
            Uma ngikhuluma ngamathegi kusobala ukuthi ngikhuluma nge-HTML, hhayi iPython. Kunoma ikuphi, uma ufaka ikhodi ngaphandle kokungena ku-Python ngeke kusebenze. Uma i-newbie ifika ikopishe ikhodi njengoba ivela kulokhu okuthunyelwe futhi izama ukuyiqhuba, izokwehluleka. Ungahle ukhungatheke njengoba ungumuntu omusha. Futhi, iphutha akulona elakho; nasempendulweni yami eyedlule engikwenzile ukunikeza indlela yokuxazulula inkinga kusuka ezingeni lomsebenzisi-okuthunyelwe.

          3.    nxumabiyela kusho

            Uqinisile impela, bekufanele ngabe ngilayishe izithombe esikhundleni sokukopisha ikhodi.
            ukukhombisa ukuthi izitatimende zi-oda kahle kanjani ku-PyGTK 3.

  7.   felipe kusho

    Ukuhlela nge-python ngincoma ukusebenzisa i-Eclipse nge-plugin yePyDev, noma i-Pychar m

  8.   ULuix kusho

    Njengoba kushiwo ngenhla, yingakho ngingathandi i-python, ngenxa yama-indent. Njengoba sibonile, ukukopisha nokunamathisela ngeke kusebenze, okungenzeki ngezinye izilimi ezinjenge-C, Java, PHP, njll.

    Into efundekayo, sisebenzisa i-code beautifier (njenge http://indentcode.net/ ) futhi isilungile,

    Okubi kulungisiwe, kepha uma kungekho induction nomqondo ushintshiwe, siyezwakala ..

  9.   Carlos kusho

    Ngimusha kuPyGTK, kungenzeka yini ukusebenzisana nemibhalo yeShell ngalolu limi?

    1.    Hola kusho

      Siyabonga ngokufundisa.

      Ukubingelela