<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Neutron on Medium]]></title>
        <description><![CDATA[Stories by Neutron on Medium]]></description>
        <link>https://medium.com/@neutron0916?source=rss-26d3578c42b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*w91-B1_TH13lYy27</url>
            <title>Stories by Neutron on Medium</title>
            <link>https://medium.com/@neutron0916?source=rss-26d3578c42b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 21:21:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@neutron0916/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Streamlit極簡易的Dashboard開發]]></title>
            <link>https://neutron0916.medium.com/streamlit%E6%A5%B5%E7%B0%A1%E6%98%93%E7%9A%84dashboard%E9%96%8B%E7%99%BC-c433e1da1559?source=rss-26d3578c42b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c433e1da1559</guid>
            <category><![CDATA[dashboard]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Neutron]]></dc:creator>
            <pubDate>Wed, 16 Dec 2020 09:06:38 GMT</pubDate>
            <atom:updated>2020-12-16T09:28:37.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N7xEQxpoKpdqKwEcRwpwsA.jpeg" /></figure><h3>前言</h3><p>資料分析的必經之路，通常就是先爬爬蟲，然後把資料畫成圖表，然後分析，網路上分享文一推，然而我在這邊也做相同的事情，不同的是使用Streamlit做個簡易的Dashboard。</p><p>Streamlit 簡易開發的程度差不多就跟<strong>味精</strong>一樣，不用什麼努力，只需簡單幾個code，就可以達成不錯的成果，是個迷人的工具。</p><p>但是，額外話，如果需要圖表跟圖表之間的互動，例如篩選圖表的內容再去另外一個圖表即時呈現，那樣的話我就會使用Dash。畢竟不同目的使用不同工具麻，炒飯就該拿鍋子，不要用什麼平底鍋，嗨壓…..</p><p>Streamlit的官方網頁-&gt; <a href="https://www.streamlit.io/">https://www.streamlit.io/</a></p><h3>成品</h3><p>這是我用steamlit 做的簡易Stock Dashboard，但是我在這邊並不會<strong>細部</strong>說明這程式怎麼寫的， 因為內部我還有自己簡單寫一個股票爬蟲，還有牽扯到plotly，所以我先把streamlit概念介紹完，再<strong>大致</strong>說明我怎麼寫的與概念。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6b6YL2ySde2GraTHP2IkuQ.gif" /></figure><h4>Code (github)</h4><p><a href="https://github.com/neutron0916/Streamlit_stock_chart">https://github.com/neutron0916/Streamlit_stock_chart</a>Streamlit</p><h3>Streamlit 概念</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lU7YeppmSvFiZmEkUDX06w.png" /></figure><p>基本上就是import streamlit as st 之後，用st…去做<strong>元件的添加</strong>。</p><p>例如想要在<br>● 網頁上添加一個名為Streamlit的標題 → st.title(“Streamlit”)<br>● 網頁加入一個輸入數字的元件，並指派到input變數內 → input = st.number_input(“num”)<br>● 網頁上添加圖表(我這邊用plotly) →st.plotly_chart(plotly圖表物件)<br>● 更多詳見 <a href="https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py">https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py</a></p><p>概念大致上是這樣，非常簡單。然後，只要<strong>輸入元件有值的變更，整個程式就會重跑一次，並重新呈現，就是因為如此，才可以做到圖表隨著輸入的參數變化。</strong></p><h3>Streamlit 簡易說明</h3><h4>Start:</h4><p>Terminal 內: <br><strong>Step1 </strong>→ pip install streamlit<br><strong>Step2 </strong>→ 寫好你的code <br><strong>Step3 </strong>→ streamlit run “你的程式.py”<br>然後就會出現以下畫面，再連上去網址就好。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*OwLhWBEznFs6l8hJeRFo4g.png" /></figure><p>有趣的是，你可以直接編輯你的程式，<strong>存檔之後，再去網頁重新整理(或是直接對網頁按R)</strong>，就可以重新跑你編輯好的程式。不需要用terminal 重新啟動</p><h3>Streamlit 元件添加</h3><p>基本上官網上的cheatsheet → <a href="https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py">https://share.streamlit.io/daniellewisdl/streamlit-cheat-sheet/app.py</a><br>已經跟你說明所有可以添加的元件了。</p><p>但是我就說明幾個常用的就好，</p><pre>st.title(‘添加標題’)<br><strong>#在網頁呈現 h1 大小的文字<br></strong>st.header(&#39;副標題&#39;)<br><strong>#在網頁呈現 h2 大小的文字</strong></pre><pre>st.write(‘寫上一些文字’)<br><strong>#在網頁呈現文字</strong></pre><pre>a = st.number_input(label = &#39;輸入一些數字&#39;, value = 預設值, step = 步數, max_value = 最大值, min_value = 最小值)<br><strong>#在網頁創建數字輸入框，然後將輸入值指派到a變數內</strong></pre><pre>b = st.text_input(&#39;輸入一些文字&#39;)<br><strong>#在網頁創建文字輸入框，然後將輸入值指派到b變數內</strong></pre><pre>c = st.selectbox(&#39;請選擇&#39;,options = [&#39;A&#39;,&#39;B&#39;,&#39;C&#39;])<br><strong>#在網頁創建選擇框，然後將輸入值指派到c變數內</strong></pre><pre>st.dataframe(dataframe) <br><strong>#在網頁將pandas的DF顯示出來</strong></pre><p><strong>輸入元件error的出現</strong></p><p>這邊要提一下如果兩個輸入框完全一模一樣會出錯</p><pre>a = st.number_input(label = &#39;請輸入數字&#39;)<br>b = st.number_input(label = &#39;請輸入數字&#39;)</pre><p>這樣就會出錯，所以至少要改一下</p><pre>a = st.number_input(&#39;請輸入數字1&#39;)<br>b = st.number_input(&#39;請輸入數字2&#39;)</pre><h4>sidebar 元件</h4><p>如果要將元件添加到就好網頁旁邊<strong>sidebar</strong>的話，很簡單，多加一個sidebar就好。例如</p><pre><em>import</em> streamlit <em>as</em> st<br>st.sidebar.header(&#39;在sidebar添加標題&#39;)<br>a = st<strong>.sidebar</strong>.number_input(label = &#39;在sidebar輸入一些數字&#39;)<br>b = st<strong>.sidebar</strong>.text_input(label = &#39;在sidebar輸入一些文字&#39;, value= &#39;請在此輸入文字&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*FOX4ZML2ftpD0jPJV_0uow.gif" /></figure><h4>加入 if 運算</h4><p>可以用if確定有一些輸入值之後再去做運算或是呈現。<br>因為只要輸入值有改變，程式就會重跑，所以a跟b 剛開始是0, 0 所以對python來說是a or b 是false，但輸入值改變之後，a跟 b 都不等於 0 的時候就是True了 ，也因為如此if 後面就有作用，就會出現在網頁上了。</p><pre><em>import</em> streamlit <em>as</em> st</pre><pre>st.title(&#39;相加&#39;)<br>a = st.number_input(label = &#39;請輸入數字1&#39;, step =1, value=0)<br>b = st.number_input(label = &#39;請輸入數字2&#39;, step =1, value=0)</pre><pre><strong><em># 確定a b 都有值之後 在輸出值<br></em></strong><em>if</em> a or b:<br>  st.write(&#39;相加結果&#39;)<br>  st.write(a+b)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gGvjAAXI4cHJNA92oXyTzA.gif" /></figure><h4>圖表元件的加入</h4><p>有很多種方式，但是st 自己內建的比較陽春。所以我是用plotly，然後再去用streamlit顯示。</p><pre>import plotly.express as px<br>import streamlit as st</pre><pre>df = px.data.iris()</pre><pre>st.dataframe(df)<br><strong>#在網頁上呈現DF</strong></pre><pre>fig = px.scatter(df, x=&quot;sepal_width&quot;, y=&quot;sepal_length&quot;, color=&quot;species&quot;, size=&#39;petal_length&#39;, hover_data=[&#39;petal_width&#39;])<br><strong>#創造一個px scatter chart的物件</strong></pre><pre>st.plotly_chart(fig)<strong><br>#在網頁上呈現plotly chart</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ID4W6Q1FBhwjZKKeuxs7zw.gif" /></figure><h4>快取的使用</h4><p>因為每次只要有輸入值的改變，網頁都必須要重新跑，所以可以利用@<em>st</em>.<em>cache</em>() 的裝飾器，就可以將<strong>之前讀取過</strong>的資料放快取，然後下次如果<strong>輸入值沒變</strong>的情況下，就可以直接將之前的data讀取出來，速度會快上取多，尤其是如果你資料的讀取非常耗時的話。</p><p>但是這個裝飾器只能用在function上，所以就必須把拿取資料的方式改成def</p><pre><em>import</em> plotly.express <em>as</em> px</pre><pre><em>import</em> streamlit <em>as</em> st</pre><pre><strong><em>@st.cache()</em></strong><br>def <em>get_data</em>():<br>  df = px.data.iris()<br>  <em>return</em> df<strong><br>#將讀取資料的方式變成function<br>#再利用st.cache()將資料放進快取內</strong></pre><pre>df = get_data()</pre><pre>st.dataframe(df)</pre><pre>fig = px.scatter(df, x=&quot;sepal_width&quot;, y=&quot;sepal_length&quot;, color=&quot;species&quot;,size=&#39;petal_length&#39;, hover_data=[&#39;petal_width&#39;])</pre><pre>st.plotly_chart(fig)</pre><p>整個streamlit 的簡介就到這邊。</p><h3>Stock chart Dashboard開發的說明</h3><p>經過以上的簡介應該streamlit都看得懂了，但是我就不說明plotly畫圖的部分，與爬蟲的使用了</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98c2eb3d6c4d43f9586956a326ebd9a0/href">https://medium.com/media/98c2eb3d6c4d43f9586956a326ebd9a0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c433e1da1559" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python-OpenCV 入門應用篇(輸出影片預覽圖)]]></title>
            <link>https://neutron0916.medium.com/python-opencv-%E5%85%A5%E9%96%80%E6%87%89%E7%94%A8%E7%AF%87-%E8%BC%B8%E5%87%BA%E5%BD%B1%E7%89%87%E9%A0%90%E8%A6%BD%E5%9C%96-2d72182752e6?source=rss-26d3578c42b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d72182752e6</guid>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Neutron]]></dc:creator>
            <pubDate>Sat, 28 Nov 2020 08:46:00 GMT</pubDate>
            <atom:updated>2020-11-28T08:46:00.947Z</atom:updated>
            <content:encoded><![CDATA[<h3>前言</h3><p>身為python的半年新手，由<strong>應用</strong>來學習是必要的。<br>一直在想說如何將程式應用在日常生活上，最終我終於想到一個好應用……</p><p>身為一個健康的男兒，都會有一個自己的專屬的動作影片資料夾，但是隨著影片越來越多，導致資料夾越來越亂。剛好我的影片資料夾的硬碟不是SSD，所以在每次挑取<strong>今晚想要欣賞的影片</strong>時，隨著開開點點，加上硬碟讀取的時間，著實浪費了不少夜晚寶貴的時間。</p><p>所以我最後決定用python來爬蟲自己的資料夾，然後將資料夾內的影片輸出預覽圖，這樣就可以直接看預覽圖，來選擇自己要的影片，這樣就可以節省我不少時間。但我在這篇文章，我只會分享如何用OpenCV將影片輸出預覽圖。</p><p>最終成果如下圖，讀取一個影片然後輸出是一個3*3的預覽圖片。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QOI_NLSw6GQ3f9up6gTGzQ.png" /><figcaption>拿浪流連的MV來作範例</figcaption></figure><h3>概念:</h3><h4>function 定義:</h4><p>希望這個python function可以輸入一些參數做一些變化<br><strong> 1. 攔數</strong>，例如輸入3 →就可以輸出3*3的預覽圖片<br>2. <strong>圖片大小，</strong>決定輸出圖片的寬跟高，因為其實寬跟高可以照影片比例就好，所以輸入只要寬，或是高，其中一個參數即可。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUtXHGUhelFEWlSWieuQBQ.png" /><figcaption>大致上的程式設計流程</figcaption></figure><h3>概念步驟:</h3><h4><strong>Step 1 圖片的抓取</strong></h4><p>抓取影片中<strong>相同間距的圖片</strong>。例如如果我要9(3*3)張，然後這9張圖片在影片中，需要要有相同間距，與開頭跟結尾也是有相同間距。如下圖所示</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_KaCmqpm0PcMounHcqYvCg.png" /></figure><h4><strong>Step 2 圖片連結</strong></h4><p>以9張圖片為例，需要將一次3張的方式做橫向連接，然後將連接後的3張做縱向連接，再來縮放到我要的大小後，最終輸出在相同目錄的資料夾。如下圖所示</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CLk_7a-eF4rXgHdRVz3SBw.png" /></figure><h3>實際步驟</h3><h4>Step 1 圖片的抓取 (整體流程)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_FCabsoLywdSbjhuIynaA.png" /></figure><h4>細部流程</h4><h4>Step 1.2 影片的參數</h4><p>相關參數，可以<strong>用get取得相關參數</strong>，其他相關參數可以參考連結: <a href="https://docs.opencv.org/4.0.0/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d"><em>https://docs.opencv.org/4.0.0/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d</em></a></p><p><strong>2. numpy的linespace的用法 (創建間隔相同的點)</strong></p><pre><strong><br>np.linspace(start, stop, num)<br>#start = 起始點<br>#stop = 終點<br>#num = 你想要在創建幾個間隔相同的點(包括起始點與終點)</strong></pre><pre><strong>example:</strong><br><strong>np.linspace(0,3,4) #輸出 array([0., 1., 2., 3.])</strong></pre><p><strong>Step 1.4 設定video的幀數與讀取影像圖片</strong></p><pre><strong>video.set(cv2.CAP_PROP_POS_FRAMES, frame) </strong><br><strong>#frame = 設定video所在的幀數 (這個必須為整數)</strong></pre><pre><strong>ret, frame = video.read() 影片以所在的幀數讀取<br>#ret = 如果讀取成功則為True</strong><br><strong>#frame = 讀取出來的圖片</strong></pre><h4>Step 2 圖片的合成 (整體流程)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Iw1R80-t9c5yQNxscoVVg.png" /></figure><h3>成果</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VDSRKM-o9SpOcfumHI2rdQ.png" /></figure><h3>收尾</h3><p>最終將整段程式碼變成一個function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecc5e15d4df1358ad32cf3d8c5e4548f/href">https://medium.com/media/ecc5e15d4df1358ad32cf3d8c5e4548f/href</a></iframe><pre>path = &#39;Waves_Wandering.mp4&#39;</pre><pre>video_preview_img(path, 3, 800, &#39;Testing_3_columns.png&#39;)<br>video_preview_img(path, 4, 800, &#39;Testing_4_columns.png&#39;)<br>video_preview_img(path, 5, 800, &#39;Testing_5_columns.png&#39;)</pre><pre>就可以更改變數執行了，得到不同的影片預覽照片了</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5GfV3HpUbXagBmbhlh4dw.png" /><figcaption>Testing_3_columns.png</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKiqBa1d_PHpdH8VBYbVGw.png" /><figcaption>Testing_4_columns.png</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k12vCt6kdhDA4SpLo7GLQg.png" /><figcaption>Testing_5_columns.png</figcaption></figure><h3>結語</h3><p>其實我這個是我建立自己的local pornhub的一個影片爬蟲，所以需要預覽圖片與影片，目前進度80%。等到建立完之後，就可以分享出來，然後只需要按一個鍵就可以讀取你的資料夾，分類，並且有即時的預覽圖與預覽影片。</p><p>喜歡就給個鼓勵，或是分享吧~謝謝收看</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d72182752e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Eel 創造個人網頁GUI桌面應用程式(入門篇)]]></title>
            <link>https://neutron0916.medium.com/python-eel-%E5%89%B5%E9%80%A0%E5%80%8B%E4%BA%BA%E7%B6%B2%E9%A0%81gui%E6%A1%8C%E9%9D%A2%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F-%E5%85%A5%E9%96%80%E7%AF%87-2500b38ed070?source=rss-26d3578c42b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2500b38ed070</guid>
            <category><![CDATA[pythongui]]></category>
            <category><![CDATA[gui]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Neutron]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 09:07:15 GMT</pubDate>
            <atom:updated>2020-10-21T10:15:56.934Z</atom:updated>
            <content:encoded><![CDATA[<h3>介紹</h3><p><strong>Eel </strong>是一個python輕量級的GUI第三方的module，可以透過local 伺服器實現web與python之間的溝通，所以整個介面會以網頁方式呈現(會用chrome開啟)，也就是可以用HTML 與CSS 去控制呈現的風格，然後用JS 與python 互相呼叫。</p><p>當然也有其他的好用GUI package可以使用，例如Tkinter or PyQt5，但是如果你剛好會網頁開發，為何不乾脆用網頁寫就好。</p><h4>技能需要</h4><p>● 基礎的 JavaScript<br>● 基礎的 HTML+CSS</p><h3>整體結構</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*qjKWPbP-kjFzuCgQclff9g.png" /></figure><p>整個程式是以python 執行，但是介面會以網頁為主。</p><h3>安裝</h3><blockquote>windows : pip install eel</blockquote><h3>使用</h3><h4><strong>資料夾結構</strong></h4><p>必須要先有固定的資料夾結構才可以開始，要有一個folder去裝網頁的檔案，例如css/html/js/img 皆是</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*ZHWgxs2eKMZKLu9FtZH2sA.png" /><figcaption><strong>與python程式同一個資料夾下，要有一個web folder專門放html/js/css檔案</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*AchD7yMpSAR4wFJHHT9Xbg.png" /><figcaption><strong>像是這樣</strong></figcaption></figure><h3><strong>起始步驟</strong></h3><p><strong>Step1.</strong> 在你的 python script(app.py) 內 import eel, 然後加入 eel.init(&#39;網頁資料夾&#39;), eel.start(&#39;html檔案的名稱&#39;) 去指定你要開啟的html檔案</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11c2bbb23f2e3ca1d57ee68125bb6788/href">https://medium.com/media/11c2bbb23f2e3ca1d57ee68125bb6788/href</a></iframe><p><strong>Step2. </strong>html 內一定要在head內引入/eel.js 這個是必不可少，因為當python在eel.init()時就會將python內要被呼叫的function 寫進去eel.js內讓你的JS檔案去做使用</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51460b22e0ba943b964e687d47036378/href">https://medium.com/media/51460b22e0ba943b964e687d47036378/href</a></iframe><p>其實就這兩個步驟就可以啟用了，你可以直接執行app.py試試。會用chrome開啟一個你在HTML的網頁。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*rYXB4Y1doZv8UCwIck0I3Q.png" /></figure><h3><strong>呼叫方式</strong></h3><p><strong>JS呼叫py</strong></p><p>主要就兩個步驟<br>1. 將py function 用@eel.expose 丟給eel<br>2. 在main.js 內 直接使用eel.python_function()即可</p><p>例如我現在要HTML內的一個button去觸發JS 的function，<br>然後讓JS的function去呼叫一個python 的function，<br>再讓這個python 的function 返回我要的文字，<br>最終將返回的文字顯示在HTML。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*4LYCqyW0Ddg-Uh-vQQ7Ivw.png" /><figcaption><strong>流程大致上是這樣</strong></figcaption></figure><p>所以我先在main.html 內創造一個button 去觸發JS function(<strong><em>btn_click</em></strong>)，再加入&lt;p&gt;tag 去放入我要返回的值。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d6014dce956c9e21c10773c09e44c5a/href">https://medium.com/media/1d6014dce956c9e21c10773c09e44c5a/href</a></iframe><p>然後在app.py內將py function(say_something) 丟給eel 給JS使用，<br><strong><em>只要在py function 上加上 &#39;@eel.expose&#39; ，然後就可以在JS裡面使用。</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7ae6b5782a7e5ec1b1d94b9b946abd2/href">https://medium.com/media/b7ae6b5782a7e5ec1b1d94b9b946abd2/href</a></iframe><p>接下來就是在main.js 內使用剛剛的python function(say_something)，只要<strong><em>&#39;eel.&#39;加上PY function的名稱</em></strong>，然後在加上個()輸入參數，就可以直接使用 python function ，最後再加上()就可以直接取python function 返回的值。</p><p>像是這樣寫 eel.say_something() 就可以直接使用 ，不過要加上一個()去取值。</p><p>不過因為JS 是非阻塞式的，所以得使用aysnc 加上await 去等待python function返值。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/deaf87c007340a3fe56b546b9b043ec8/href">https://medium.com/media/deaf87c007340a3fe56b546b9b043ec8/href</a></iframe><p>最終呈現的會如下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*zmsfTyhRtdjYgRZphx0xqg.gif" /></figure><p><strong>python function 呼叫JS</strong></p><p>1. 將JS function 用eel.expose(&#39;JS function name&#39;) 丟給eel<br>2. 在app.py內 直接使用eel.JS_function()即可</p><p>基本上跟python function 丟給eel一樣，不一樣的是JS 是要加<strong> ‘eel.expose(JS function 名稱)’</strong></p><p>例如我要將main.js 內的 JS function (js_bigger)丟給python使用，則是在main.js 寫上<strong>eel.expose(js_bigger)</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc5d556539ca5c86b01a255913e2ce4b/href">https://medium.com/media/dc5d556539ca5c86b01a255913e2ce4b/href</a></iframe><p>然後在main.py 使用，使用的方式也是一樣，直接寫<strong><em>eel.</em>js_bigger<em>()</em></strong>就可以使用，然後如果有返值的話再加上()就好。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cdbda0855863ca596053f451eeea9ae/href">https://medium.com/media/3cdbda0855863ca596053f451eeea9ae/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*i4n9Xt-HFEgFmRTy81XDCg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2500b38ed070" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>