Cov txheej txheem:
- Kauj ruam 1: Qhia rau GUI
- Kauj Ruam 2: Tsim Peb Tus Kheej Tus Kheej
- Kauj ruam 3: Txheej txheem
- Kauj Ruam 4: Cov Ntsiab Lus Ntxiv (Ntu 1-Dialogue Box Exception Handling)
- Kauj Ruam 5: Cov Ntsiab Lus Ntxiv (Ntu 2-Tsim EXE)
- Kauj Ruam 6: Xaus
Video: Yuav Ua Li Cas Thiaj Li Ua Ntej Ua Ntej Yooj Yim Software Siv Python: 6 Cov Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:25
Nyob zoo, txais tos rau Cov Lus Qhia no. Ntawm no kuv yuav qhia yuav ua li cas thiaj ua rau koj tus kheej software. Yog tias koj muaj lub tswv yim … tab sis paub paub siv lossis xav tsim yam tshiab ces nws yog rau koj ……
Yam yuavtsum tau kawm uantej: Yuav tsum muaj kev paub txog Python…. LOL Tsis muaj dab tsi zoo li ntawd, "Tsis muaj ib yam nyuaj hauv ntiaj teb no yog koj sim"
nrog kev txaus siab yooj yim los ua tej yam uas koj tuaj yeem txav mus pib koj li haujlwm. Txawm tias kuv thaum pib tsis muaj Lub Tswv Yim ntawm nab hab sej.
Ntxiv mus raws li Hluav Taws Xob thaum xub thawj kuv ntshai Coding. Maj mam kuv hloov kuv lub siab.
Yog tias koj yog tus pib ntawm lub cajmeem, pib nrog nab hab sej ua rau nkhaus nrawm los kawm thiab raws li cov txiaj ntsig tau nrawm heev koj tau txais kev zoo siab heev los kawm.
OK tsis tas nkim sijhawm ntau peb tuaj yeem txav mus rau qhov kev kawm.
Ntawm no hauv cov lus qhia no kuv tsuas yog yuav qhia yuav ua li cas thiaj ua tau yooj yim GUI nrog nab hab sej yuav ua li cas thiaj ua tau nws mus rau hauv Software nrog "exe" thiab tsis ntau nrog cov nab nab npawb coding ….. koj tuaj yeem xa mus rau youtube lossis udemy kom kawm Python
koj tuaj yeem nruab sej los ntawm no:
Kauj ruam 1: Qhia rau GUI
Ua ntej, peb yuav tsum pib GUI. Tsis muaj dab tsi tab sis Graphical User Interface rau tag nrho koj cov lej.
Ntawd yog koj yuav tau ua haujlwm rau ntawm kab hais kom ua thiab tau txais cov txiaj ntsig zoo ib yam. Tab sis txhawm rau ua kom koj cov cai cuam tshuam nrog tus neeg siv koj xav tau Kev Sib Txuas los sib tham.
Tsim GUI nrog nab hab sej yog qhov yooj yim heev … Cia pib
Muaj ntau qhov qauv hauv nab hab sej uas koj tuaj yeem ntshuam thiab sau koj li GUI. Tkinter yog GUI built-in rau tus nab hab sej, Nws los nruab nrog koj li nab hab sej software. Tsis tas li, koj kuj tseem tuaj yeem sim PyQT, Kivy (zoo tshaj rau hla-platform piv txwv li cov cai hauv nab hab sej tuaj yeem siv los tsim apk, exe lossis MAC software)
Nov yog hauv Cov Lus Qhia no, Kuv yuav siv Tkinter. Qhov yooj yim hauv nab nab yog tias koj tuaj yeem xa lwm cov ntaub ntawv nab nab mus rau koj, tib txoj kev koj yuav tsum tau ntshuam Tkinter nab hab sej, zoo ib yam li #suav nrog hauv C.
los ntawm Tkinter ntshuam *ntshuam Tkinter ntshuam tkMessageBox sab saum toj = Tk () L1 = Ntawv cim (sab saum toj, ntawv = "HI") L1.pack (sab = LEFT) E1 = Nkag mus (saum, bd = 5) E1.pack (sab = RIGHT)) B = Khawm (saum, ntawv = "Nyob Zoo",) B.pack ()
top.mainloop ()
Piav qhia:
ntawm no Tk () hais txog chav kawm hauv
Tkinter module peb tau txuag kev pib ua rau saum, Daim ntawv lo yog txheej txheem (ua haujlwm zoo li lwm yam lus) los luam cov ntawv hauv, Txoj hauv kev nkag los tsim qhov nkag nkag dawb thiab
Khawm yog los tsim khawm, Yooj yim li ntawd…. Nws tsis yog
pob yog qhov tseem ceeb rau pob txhua yam nws teeb tsa…. thaum kawg lub voj tseem ceeb khaws txhua yam pom kom txog thaum koj kaw GUI
Kauj Ruam 2: Tsim Peb Tus Kheej Tus Kheej
Tam sim no peb tau pom qhov yooj yim GUI nrog cov nyees khawm, Yog li vim li cas thiaj tos, cia pib tsim lub tshuab xam zauv yooj yim nrog cov nyees khawm.
Nco tseg:
Muaj peev xwm muaj tus lej ntawm txoj hauv kev tsim cov cai, ntawm no kuv tsuas yog qhia tus lej uas yooj yim dua rau kuv
Kauj Ruam 1: Tsim GUI
Ua ntej yuav mus rau tus lej peb tuaj yeem tsim GUI rau peb daim ntawv thov laij lej.
Ntawm no kuv yuav siv tsuas yog ib lub pob thiab 4-kab nkag nkag kom nkag siab yooj yim.
yog li cov ntawv yooj yim muab tshuaj txhuam ntawm txhua daim ntawv lo, nkag thiab khawm peb tsim ntawm cov kauj ruam dhau los … Tsis txhob poob siab los ntawm qhov ntev ntawm txoj cai …! haha
los ntawm Tkinter ntshuam *ntshuam Tkinter ntshuam tkMessageBox
top = Tkinter. Tk () L1 = Label (sab saum toj, ntawv = "Kuv lub laij lej",).grid (kab = 0, kab lus = 1) L2 = Label (sab saum toj, ntawv = "Tus lej 1",).grid (kab ntawv = 1, kab ntawv = 0) L3 = Daim ntawv lo (sab saum toj, ntawv = "Tus lej 2",).grid (kab = 2, kab lus = 0) L4 = Daim ntawv lo (sab saum toj, ntawv = "Tus Neeg Siv Khoom",).grid (kab lus = 3, kab ntawv = 0) L4 = Daim ntawv lo (sab saum toj, ntawv = "Teb",).grid (kab = 4, kab ntawv = 0) E1 = Nkag mus (sab saum toj, bd = 5) E1.grid (kab ntawv = 1, kab lus = 1) E2 = Nkag mus (saum, bd = 5) E2.grid (kab = 2, kab ntawv = 1) E3 = Nkag mus (saum, bd = 5) E3.grid (kab = 3, kab ntawv = 1) E4 = Nkag mus (saum, bd = 5) E4.grid (kab = 4, kab ntawv = 1) B = Khawm (saum, ntawv = "Xa",).grid (kab ntawv = 5, kab ntawv = 1,)
top.mainloop ()
Kauj Ruam 2: Txoj Cai Tseem Ceeb
Nov ntawm peb qhov xwm txheej yuav tsum tshwm sim … tom qab nkag mus rau 2 tus lej thiab qhia meej txog kev ua haujlwm ntawm lawv, cov lus teb yuav tsum tau luam tawm lossis nthuav tawm hauv cov lus teb nkag.
1. Submit khawm hais kom ua:
Peb yuav tsum tau muab cov lus txib rau lub pob kom hu tus txheej txheem uas yog yam uas tau tsim. Cia peb pom…
B = Khawm (saum, ntawv = "Xa", hais kom ua = ua).grid (kab ntawv = 5, kem = 1)
def proces (): number1 = Entry.get (E1) number2 = Entry.get (E2) tus neeg teb xov tooj = Entry.get (E3)
Ntawm no kuv tau hu ua Txheej Txheem (txheej txheem) txheej txheem, yog li tom qab nias lub pob program mus thiab khob qhov rooj ntawm txoj haujlwm ua haujlwm hauv cov lus yooj yim dua.
thiab tau txais ntawm no txhais tau tias tau txais tus nqi uas tus neeg siv nkag mus. Tsis tas li, kuv khaws hauv 3 qhov sib txawv xws li tus lej 1, tus lej 2, tus neeg teb xov tooj
Tsuas yog ua kom muaj txiaj ntsig Kuv tau khaws cov txheej txheem koj tuaj yeem khaws lub npe ntawm txoj hauv kev raws li qhov koj xav tau.
Kauj ruam 3: Txheej txheem
Hauv cov kauj ruam no, peb yuav tsum ua cov txheej txheem tau txais los ntawm tus neeg siv, Tab sis los ntawm lub neej ntawd, tus nqi tau txais yog txoj hlua.
Yog li yuav ua li cas hloov nws mus rau tus lej kom ua qhov suav …?
Yog li tsis muaj dab tsi txhawj xeeb nws yog nab nab thiab tsis yog C lossis C ++ los nyem koj lub hlwb.
Cias nkag mus rau qhov sib txawv hauv int (sib txawv)
number 1 = int (tus lej 1) tus lej 2 = int (tus lej 2)
Tseem, muaj lwm qhov teeb meem… yuav ua li cas kom tau tus nqi ntawm tus neeg teb xov tooj (zoo li +, -*/) kom ua haujlwm ???
Tsuas yog ua yog nqe lus rau txhua tus thiab sab hauv ua qhov kev suav.
number1 = int (number1) number2 = int (number2) yog tus neeg teb xov tooj == "+": teb = number1+number2 yog tus neeg teb xov tooj == "-": teb = number1-number2 yog tus neeg teb xov tooj == "*": teb = number1* tus lej 2 yog tus neeg teb xov tooj == "/": teb = tus lej 1/tus lej 2
Txoj hlua nyob hauv nab nab yog qhia los ntawm "" uas nyob ntawm no yog tias peb tab tom kuaj xyuas tus neeg teb xov tooj tau txais los ntawm tus neeg siv mus rau txoj hlua +, -, */ etc, thiab khaws cov txiaj ntsig hauv cov lus teb sib txawv.
Tam sim no thaum kawg peb yuav tsum xa cov ntawv xa mus rau cov lus teb nkag, qhov no yog ua los ntawm tus lej nkag.
Nkag mus.insert (E4, 0, teb)
yog li thaum kawg peb cov cai zoo li:
los ntawm Tkinter ntshuam *ntshuam Tkinter ntshuam tkMessageBox def proces (): number1 = Entry.get (E1) number2 = Entry.get (E2) operator = Entry.get (E3) number1 = int (number1) number2 = int (number2) yog tus neeg teb xov tooj == "+": teb = tus naj npawb 1+tus lej 2 yog tus neeg teb xov tooj == "-": teb = tus naj npawb 1-tus lej 2 yog tus neeg teb xov tooj == "*": teb = tus lej 1*tus lej 2 yog tus neeg teb xov tooj == "/": teb = tus naj npawb 1/ number2 Nkag mus.insert (E4, 0, teb) luam tawm (teb)
saum = Tkinter. Tk ()
L1 = Daim ntawv lo (sab saum toj, ntawv = "Kuv lub laij lej",).grid (kab = 0, kab ntawv = 1) L2 = Daim ntawv lo (sab saum toj, ntawv = "Tus lej 1",).grid (kab ntawv = 1, kab lus = 0) L3 = Daim ntawv lo (sab saum toj, ntawv = "Tus lej 2",).grid (kab ntawv = 2, kab ntawv = 0) L4 = Daim ntawv lo (sab saum toj, ntawv = "Tus Neeg Ua Haujlwm",).grid (kab ntawv = 3, kab lus = 0) L4 = Label (saum, ntawv = "Teb",).grid (kab = 4, kab ntawv = 0) E1 = Nkag mus (saum, bd = 5) E1.grid (kab = 1, kab ntawv = 1) E2 = Nkag mus (saum, bd = 5) E2.grid (row = 2, column = 1) E3 = Entry (top, bd = 5) E3.grid (row = 3, column = 1) E4 = Entry (top, bd = 5) E4.grid (kab = 4, kab ntawv = 1) B = Khawm (saum, ntawv = "Xa", hais kom ua = txheej txheem).grid (kab = 5, kab ntawv = 1,)
top.mainloop ()
WOW, koj tau ua tiav tsim cov lej ntawm lub laij lej …….. !! Nws txog sijhawm ua kev zoo siab..
Kauj Ruam 4: Cov Ntsiab Lus Ntxiv (Ntu 1-Dialogue Box Exception Handling)
Lub taub hau Suab zoo li ib yam dab tsi….? Yeej tsis yog kuv yuav qhia koj zaj dab neeg vim li cas, …
Xav txog koj tau ua lub laij lej no thiab qhia nws rau phooj ywg.
Nws/nws yog tus neeg muaj suab npe es tsis txhob ntaus tus lej nws ntaus ntawv hauv tus lej nkag thiab cov menyuam koj … yuav ua li cas …? nab hab sej ua rau yuam kev thiab nres tam sim ntawd….
Nov los txog txheej txheem ntawm cov nab nab tshwj tseg kev tuav pov hwm, kuj nyob hauv ntau lub software thiab nplooj ntawv web tsim tawm ceeb toom lossis ceeb toom cov lus
Zam Kev Ua Haujlwm hauv nab hab sej
Kev zam tshwj xeeb yog yooj yim tau hais sim thiab yog tias muaj qhov ua yuam kev qhia ceeb toom
Ntaus tus nqi ntawm cov ntawv hauv lub console hais tias Tus nqi yuam kev yog li nws peb tuaj yeem ua qhov ceeb toom
Cia peb pom yuav ua li cas hauv peb cov cai:
def proces (): sim: number1 = Entry.get (E1) number2 = Entry.get (E2) operator = Entry.get (E3) number1 = int (number1) number2 = int (number2) if operator == "+": teb = tus naj npawb 1+tus lej 2 yog tus neeg teb xov tooj == "-": teb = tus naj npawb 1-tus lej 2 yog tus neeg teb xov tooj == "*": teb = tus lej 1*tus lej 2 yog tus neeg teb xov tooj == "/": teb = tus lej 1/tus lej 2 nkag.insert (E4, 0, teb) luam tawm (teb) tshwj tsis yog ValueError: tkMessageBox.showwarning ("Ceeb Toom", "Thov sau tus nqi hauv tus lej")
Nov peb tau ua qhov yooj yim ceeb toom lub thawv sib tham thiab ntawm no zoo li ua ntej tkMessageBox.showwarning yog qhov kev ceeb toom tshwj xeeb rau Tkinter thiab hauv kab lus ceeb toom ceeb toom qhia txog lub ntsiab lus ntawm lub npov sib tham thiab tom ntej no qhia cov lus.
Kauj Ruam 5: Cov Ntsiab Lus Ntxiv (Ntu 2-Tsim EXE)
Xav txog qhov tseeb tias koj tau tsim koj tus lej nab npawb, thiab ua haujlwm tiav tom qab debugging tsis raug … Tsis tas li Yog tias koj xav tsis qhia koj cov cai tsim EXE yog txoj hauv kev zoo tshaj.
yog li txhawm rau tsim qhov ua tiav (exe) version lossis Apk (rau Android) yuav tsum tau ua qhov no tuaj yeem ua los ntawm khov koj cov cai.
Muaj ntau ntau txoj hauv kev xaiv kom khov koj tus lej ib qho kuv xav qhia yog siv Pyinstaller.
theem 1:
www.pyinstaller.org/ Nruab los ntawm no thiab ua raws li lawv cov kauj ruam yog tias koj nkag siab tsis tau, saib koj lub raj qhia kom teeb tsa lub pyinstaller software.
Kauj ruam 2:
Tom qab ntawd mus rau daim nplaub tshev uas qhov chaws nyob tam sim no thiab nias SHIFT +txoj nyem rau hauv nas khawm thiab nyem qhib hauv qhov hais kom ua tam sim lossis lub zog plhaub nyob ntawm koj li OS version.
nab hab sej pyinstaller.py --noconsole yourscript.py
pyinstaller.exe --onefile --windowed -npe myapps --icon = yourico.ico yourscript.py
Yog li koj kuj tseem tuaj yeem ntxiv koj ico rau koj exe thiab ntim nws hauv ib daim ntawv nrog cov lus txib thib ob.
Kauj Ruam 6: Xaus
Yog li Nws nyob ntawm koj qhov kev txaus siab los tsim qhov software kawg,… Ua tsaug rau kev nyeem Kuv yuav tso cov lej kawg thiab exe hauv kuv li GitHub txuas >>
Tsis tas li, kuv tau tsim 2 software
1. Blender Batch Renderer
Piav qhia luv:
Blender yog cov software tsim tawm uas peb siv los ua cov khoom ua yeeb yam.
Nws siv sijhawm ntev heev los muab cov txiaj ntsig, tsis muaj kev xaiv nyob hauv lub tshuab ziab khaub ncaws kom ncua thiab ua haujlwm nruab nrab, yog li kuv tau tsim software rau nws … Nws yooj yim me ntsis ….. tsis nyuaj rau kuv rau code thaum pib yam tsis muaj kev pab.. kawg ua tau. (nws qhia kuv tsis muaj dab tsi nyuaj yog tias koj sim).
2. Kev Siv Hluav Taws Xob Nruas Beats Arduino rau lub computer txuas
Piav qhia luv:
Nws yog software uas tuaj yeem nyeem piezo sensor los ntawm Arduino thiab nab hab sej software yuav ua suab paj nruag raws li. (Qhov no tau ua rau kuv tus phooj ywg uas nug nws ntev heev….)
Cov Lus Qhia no tsuas yog qhia paub tsim software los ntawm nab hab sej raws li kuv nkag siab,…. thov txim Yog tias kuv ua tsis raug ntawm ib feem twg, raws li tus pib kho kuv hauv cov lus.
Ua tsaug rau kuv tus you tube channel engineer xav rau cov vis dis aus yav tom ntej: Cov kws paub xav
Kuv tseem yuav ntxiv ntxiv hauv kuv Lub Vev Xaib: www.engineerlookts.com
Tsis ntev kuv yuav ua tus qhia rau kuv software.
Xav tias dawb nug ib qho kev ua xyem xyav hauv nqe lus. Kuv yuav zoo siab Yog tias koj tau txais txiaj ntsig los ntawm qhov kev qhia no
Ua Vajtswv tsaug thiab sawv daws
zoo siab, Vajtswv nyob nrog koj … txhua qhov zoo tshaj plaws
Nrog kev hlub
(N. Aranganathan)
Pom zoo:
D.I.Y YOOJ YIM YOOJ YIM YOOJ YIM YOOJ YIM YOOJ YIM LOS NTAWM SCRAPS: 4 Cov Kauj Ruam (nrog Duab)
D.I.Y YOOJ YIM YOOJ YIM YOOJ YIM YOOJ YIM LOS NTAWM SCRAPS: Hnub no kuv xav qhia yuav ua li cas kom pom lub teeb pom kev zoo los ntawm lub zog xa hluav taws xob tsis siv hluav taws xob los ntawm tus txhuam txhuam hniav thiab lub tshuab solenoid valve coils uas tau khaws los ntawm scrapyard.Ua ntej pib, thov saib cov vis dis aus hauv qab no:
Txoj Kev Yooj Yim thiab Yooj Yim Los Hloov Koj Lub Xauv Screen hauv 6 Cov Kauj Ruam Yooj Yim (Windows 8-10): 7 Kauj Ruam
Txoj Kev Yooj Yim thiab Yooj Yim Los Hloov Koj Lub Xauv Screen hauv 6 Cov Kauj Ruam Yooj Yim (Windows 8-10): Xav hloov pauv yam ntawm koj lub laptop lossis PC? Xav tau kev hloov pauv hauv koj qhov chaw? Ua raws cov kauj ruam no yooj yim thiab yooj yim kom ua tiav koj tus kheej lub computer ntsuas phoo
YUAV UA LI CAS YOOJ YIM YOOJ YIM YOOJ YIM YOOJ YIM YOOJ YIM TSHAJ PLAWS YOOJ YIM: 4 Cov Kauj Ruam
YUAV UA LI CAS YOOJ YIM YOOJ YIM YOOJ YIM YOOJ YIM YOOJ YIM TSHAJ PLAWS: Nyob zoo txhua tus hauv cov lus qhia no kuv yuav qhia koj yuav ua li cas kom yooj yim " SOIL DRYNESS SENSOR ". Qhuav ntawm cov av tau txheeb xyuas siv qhov taw qhia coj. Lub teeb ci wi
Ib qho yooj yim heev/yooj yim/Tsis yooj yim txoj hauv kev kom tib neeg/tib neeg/tsiaj/neeg hlau zoo li lawv muaj txias tiag tiag/Lub zeem muag tshav kub kub (Xim ntawm Koj Xaiv) Siv GIMP: 4 Cov Kauj Ruam
Ib qho yooj yim heev/yooj yim/Tsis yooj yim txoj hauv kev kom tib neeg/tib neeg/tsiaj/neeg hlau zoo li lawv muaj txias tiag tiag/Lub zeem muag tshav kub kub (Xim ntawm Koj Xaiv) Siv GIMP: Nyeem … lub npe
Yuav Ua Li Cas Thiaj Li Yooj Yim Yooj Yim 'Calendar & Scrapbook (txawm hais tias Koj Tsis Paub Yuav Ua Li Cas Scrapbook): 8 Kauj Ruam (nrog Duab)
Yuav Ua Li Cas Thiaj Li Yooj Yim Yooj Yim 'Calendar & Scrapbook (txawm hais tias Koj Tsis Paub Yuav Ua Li Cas Scrapbook): Nov yog qhov kev lag luam pheej yig (thiab muaj txiaj ntsig ntau!) Hnub so khoom plig rau niam tais yawm txiv. Kuv tau ua 5 daim qhia hnub hli xyoo no rau tsawg dua $ 7 txhua qhov khoom siv: 12 daim duab zoo ntawm koj tus menyuam, menyuam yaus, ntxhais xeeb ntxwv, tub xeeb ntxwv, dev, miv, lossis lwm tus txheeb ze 12 daim sib txawv