<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tkinter｜python-manブログ</title>
	<atom:link href="https://python-man.club/category/python/tkinter/feed/" rel="self" type="application/rss+xml" />
	<link>https://python-man.club</link>
	<description>独学者でもpythonでアプリを作れる！</description>
	<lastBuildDate>Fri, 03 Jun 2022 22:51:49 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.2</generator>
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>pythonのtkinterでメニューバーを作成しよう【サンプルコードあり】</title>
		<link>https://python-man.club/python_tkinter_menubar/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python_tkinter_menubar</link>
					<comments>https://python-man.club/python_tkinter_menubar/#respond</comments>
		
		<dc:creator><![CDATA[syou0445]]></dc:creator>
		<pubDate>Sun, 29 May 2022 07:37:09 +0000</pubDate>
				<category><![CDATA[python]]></category>
		<category><![CDATA[tkinter]]></category>
		<category><![CDATA[python tkinter メニューバー]]></category>
		<guid isPermaLink="false">https://python-man.club/?p=1182</guid>

					<description><![CDATA[pythonでGUIアプリを使っていると、メニューバーを作成する機会が出てきます この記事では、pythonのtkinterを使って、メニューバーを作成する方法について解説していきたいと思います 入れ子構造のメニューバー]]></description>
										<content:encoded><![CDATA[<p>pythonでGUIアプリを使っていると、メニューバーを作成する機会が出てきます</p>
<p>この記事では、pythonのtkinterを使って、メニューバーを作成する方法について解説していきたいと思います</p>
<p><strong><span class="marker">入れ子構造のメニューバー作成方法については、ネット上になかなか転がっていないので、参考になるかと思います</span></strong></p>
<div class="simple-box2">
<p style="text-align: center;"><strong>この記事でわかること</strong></p>
<ul>
<li style="text-align: left;"><strong>tkinterでメニューバーを作成する方法</strong></li>
<li style="text-align: left;"><strong>tkinterで入れ子構造のメニューバーを作る方法</strong></li>
<li style="text-align: left;"><strong>tkinterの使い方を知る</strong></li>
</ul>
</div>
<h2>pythonのtkinterでメニューバーを作成する</h2>
<img fetchpriority="high" decoding="async" class="alignnone size-large wp-image-1189" src="https://python-man.club/wp-content/uploads/2022/05/jefferson-santos-9SoCnyQmkzI-unsplash-1024x683.jpg" alt="python tkinter h2" width="1024" height="683" srcset="https://python-man.club/wp-content/uploads/2022/05/jefferson-santos-9SoCnyQmkzI-unsplash-1024x683.jpg 1024w, https://python-man.club/wp-content/uploads/2022/05/jefferson-santos-9SoCnyQmkzI-unsplash-300x200.jpg 300w, https://python-man.club/wp-content/uploads/2022/05/jefferson-santos-9SoCnyQmkzI-unsplash-768x512.jpg 768w, https://python-man.club/wp-content/uploads/2022/05/jefferson-santos-9SoCnyQmkzI-unsplash-1536x1024.jpg 1536w, https://python-man.club/wp-content/uploads/2022/05/jefferson-santos-9SoCnyQmkzI-unsplash.jpg 1920w, https://python-man.club/wp-content/uploads/2022/05/jefferson-santos-9SoCnyQmkzI-unsplash-1024x683.jpg 856w" sizes="(max-width: 1024px) 100vw, 1024px" />
<p>pythonのtkinterモジュールを使用することで、メニューバーを作成することができます</p>
<p>GUIアプリでは、メニューバーは必須となります</p>
<p>イメージとしては、以下のようなものを作成していきます</p>
<img decoding="async" class="alignnone size-full wp-image-1183" src="https://python-man.club/wp-content/uploads/2022/05/スクリーンショット-2022-05-29-15.48.01.png" alt="python tkinter メニューバー" width="558" height="43" />
<h3>ボタンクリック時のイベントを定義する</h3>
<p>それぞれのメニューには、イベントを付与することができます</p>
<p>例えば、「ファイルを選択する」を選んだ時には、ファイルダイアログが展開されるように定義をしておくことができます</p>
<p>イベントの定義は以下のように定義をします</p>
<pre class="language-python"><code># メニューから呼び出される関数
# passに実行したい内容のコードを記載する
def open_file():
    pass
def close_disp():
    pass
</code></pre>
<h2>pythonのtkinterでメニューバーを作成するサンプルコード</h2>
<img decoding="async" class="alignnone size-large wp-image-1190" src="https://python-man.club/wp-content/uploads/2022/05/shahadat-rahman-BfrQnKBulYQ-unsplash-1024x683.jpg" alt="python tkinter h2-2" width="1024" height="683" srcset="https://python-man.club/wp-content/uploads/2022/05/shahadat-rahman-BfrQnKBulYQ-unsplash-1024x683.jpg 1024w, https://python-man.club/wp-content/uploads/2022/05/shahadat-rahman-BfrQnKBulYQ-unsplash-300x200.jpg 300w, https://python-man.club/wp-content/uploads/2022/05/shahadat-rahman-BfrQnKBulYQ-unsplash-768x512.jpg 768w, https://python-man.club/wp-content/uploads/2022/05/shahadat-rahman-BfrQnKBulYQ-unsplash-1536x1024.jpg 1536w, https://python-man.club/wp-content/uploads/2022/05/shahadat-rahman-BfrQnKBulYQ-unsplash.jpg 1920w, https://python-man.club/wp-content/uploads/2022/05/shahadat-rahman-BfrQnKBulYQ-unsplash-1024x683.jpg 856w" sizes="(max-width: 1024px) 100vw, 1024px" />
<p>実際にtkinterのサンプルコードを使って、コードを書いていきましょう</p>
<pre class="language-python"><code>import tkinter as tk

#ウインド画面の作成
root=tk.Tk()

# メニューから呼び出される関数
def open_file():
    pass
def close_disp():
    pass
# menubarの大元（コンテナ）の作成と設置
menubar = tk.Menu(root)
root.config(menu=menubar)
#メニューに親メニュー（ファイル）を作成する 
menu_file = tk.Menu(root) 
menubar.add_cascade(label='ファイル', menu=menu_file) 

#親メニューに子メニュー（開く・閉じる）を追加する 
menu_file.add_command(label='開く', command=open_file) 
menu_file.add_command(label='閉じる', command=close_disp)

#画面の表示
root.mainloop()</code></pre>
<p>上記のコードで以下のようなメニューバーが作成できるかと思います</p>
<img decoding="async" class="alignnone size-full wp-image-1184" src="https://python-man.club/wp-content/uploads/2022/05/スクリーンショット-2022-05-29-16.04.14.png" alt="python tkinter メニューバーサンプル" width="208" height="260" />
<h3>メニューバーの作成</h3>
<p>メニューバーの作成は以下の部分で行なっています</p>
<pre class="language-python"><code>#メニューに親メニュー（ファイル）を作成する 
menu_file = tk.Menu(root) 
menubar.add_cascade(label='ファイル', menu=menu_file) </code></pre>
<p>さらにメニューバーを増やすこともできます</p>
<pre class="language-python"><code>import tkinter as tk

#ウインド画面の作成
root=tk.Tk()

# メニューから呼び出される関数
def open_file():
    pass
def close_disp():
    pass

# menubarの大元（コンテナ）の作成と設置
menubar = tk.Menu(root)
root.config(menu=menubar)

#メニューに親メニュー（ファイル）を作成する 
menu_file = tk.Menu(root) 
menubar.add_cascade(label='ファイル', menu=menu_file) 

# menubarを親としてヘルプメニューを作成と表示
help_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label='ヘルプ', menu=help_menu)

#親メニューに子メニュー（開く・閉じる）を追加する 
menu_file.add_command(label='開く', command=open_file) 
menu_file.add_command(label='閉じる', command=close_disp)

#画面の表示
root.mainloop()</code></pre>
<img decoding="async" class="alignnone size-full wp-image-1185" src="https://python-man.club/wp-content/uploads/2022/05/スクリーンショット-2022-05-29-16.07.03.png" alt="python tkinter メニューバーサンプル2" width="229" height="257" />
<h3>入れ子構造のメニューバーを作成する</h3>
<p>実際には、入れ子構造になっているメニューバーがほとんどなので、入れ子構造のメニューバーも作成していきたいと思います</p>
<pre class="language-python"><code>import tkinter as tk

#ウインド画面の作成
root=tk.Tk()

# メニューから呼び出される関数
def open_file():
    pass
def close_disp():
    pass

# menubarの大元（コンテナ）の作成と設置
menubar = tk.Menu(root)
root.config(menu=menubar)

#メニューに親メニュー（ファイル）を作成する 
menu_file = tk.Menu(root) 
menubar.add_cascade(label='ファイル', menu=menu_file) 

# menubarを親としてヘルプメニューを作成と表示
help_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label='ヘルプ', menu=help_menu)

#親メニューに子メニュー（開く・閉じる）を追加する 
menu_file.add_command(label='開く', command=open_file) 
menu_file.add_command(label='閉じる', command=close_disp)

#入れ子構造のメニューバー
cascade_a_1 = tk.Menu(menu_file,tearoff=False)
menu_file.add_cascade(label="開く",menu=cascade_a_1)
cascade_a_1.add_command(label="新規ファイルを開く",command=open_file)
cascade_a_1.add_command(label="既存ファイルを開く",command=open_file)
cascade_a_1.add_command(label="デスクトップから開く",command=open_file)
#画面の表示
root.mainloop()</code></pre>
<img decoding="async" class="alignnone size-full wp-image-1186" src="https://python-man.club/wp-content/uploads/2022/05/スクリーンショット-2022-05-29-16.09.42.png" alt="python tkinter メニューバー3" width="345" height="253" />
<p>これで入れ子構造のメニューバーを作成することができました</p>
<p>あらかじめイベントを複数定義しておき、「<strong>command</strong>」の内容を変更しておくことで、それぞれ、異なった挙動をさせることができます</p>
<h2>python初心者がプログラミングで収益を出す方法</h2>
<img decoding="async" class="alignnone size-large wp-image-1075" src="https://python-man.club/wp-content/uploads/2022/04/micheile-dot-com-ZVprbBmT8QA-unsplash-1024x683.jpg" alt="python twitter 稼ぐ方法" width="1024" height="683" srcset="https://python-man.club/wp-content/uploads/2022/04/micheile-dot-com-ZVprbBmT8QA-unsplash-1024x683.jpg 1024w, https://python-man.club/wp-content/uploads/2022/04/micheile-dot-com-ZVprbBmT8QA-unsplash-300x200.jpg 300w, https://python-man.club/wp-content/uploads/2022/04/micheile-dot-com-ZVprbBmT8QA-unsplash-768x512.jpg 768w, https://python-man.club/wp-content/uploads/2022/04/micheile-dot-com-ZVprbBmT8QA-unsplash-1536x1024.jpg 1536w, https://python-man.club/wp-content/uploads/2022/04/micheile-dot-com-ZVprbBmT8QA-unsplash.jpg 1920w, https://python-man.club/wp-content/uploads/2022/04/micheile-dot-com-ZVprbBmT8QA-unsplash-1024x683.jpg 856w" sizes="(max-width: 1024px) 100vw, 1024px" />
<p>python初心者がプログラミングで収益を出すには、以下の方法があります</p>
<ul>
<li><strong>note</strong></li>
<li><strong>ココナラ</strong></li>
<li><strong>ブログ</strong></li>
<li><strong>オンラインサロン</strong></li>
<li><strong>コンサル</strong></li>
<li><strong>アフィリエイト</strong></li>
</ul>
<p>上記の方法に加え、SNSを活用することで、収益化は一気に速くなります</p>
<a href="https://python-man.club/python_twitter_labour/" class="blog-card"><div class="blog-card-hl-box"><i class="jic jin-ifont-post"></i><span class="blog-card-hl"></span></div><div class="blog-card-box"><div class="blog-card-thumbnail"><img decoding="async" src="https://python-man.club/wp-content/uploads/2022/04/今年のうちに読むべき書籍-32-320x180.jpg" class="blog-card-thumb-image wp-post-image" alt="python twitter 稼ぐ" width ="162" height ="91" /></div><div class="blog-card-content"><span class="blog-card-title">pythonを使ってtwitterで稼ぐ仕組みを作る方法【サンプルコードあり】</span><span class="blog-card-excerpt">pythonを学び始めた理由に、「稼ぎたいから」という理由の方が多いと思います。僕がpythonを学び始めた理由の一つに「稼ぎたいから」という理由がありました。クラウドワークスやココナラ、ランサーズなどの案件を見ていても、高単価の案件ばかりです。しかし、python初心者がいきなり高単価案件を受けれるわけではありません。そこで、この記事では、python初心者でもできる、pythonを使ってtwitterで稼ぐ仕組みを作る方法について、解説をしていきたいと思います。
実際に私が収益を出した方法なので、サンプルコードを使ってもらえれば、稼ぐことができます...</span></div></div></a>
<a href="https://python-man.club/python_revenue/" class="blog-card"><div class="blog-card-hl-box"><i class="jic jin-ifont-post"></i><span class="blog-card-hl"></span></div><div class="blog-card-box"><div class="blog-card-thumbnail"><img decoding="async" src="https://python-man.club/wp-content/uploads/2022/02/今年のうちに読むべき書籍-320x180.jpg" class="blog-card-thumb-image wp-post-image" alt="アイキャッチ" width ="162" height ="91" /></div><div class="blog-card-content"><span class="blog-card-title">pythonを独学で学び収益を出す方法【無料特典あり】</span><span class="blog-card-excerpt">pythonを独学で学び始めて筆者が、どのように収益5桁を達成したのかを具体的に解説していきます。この順番に進めていけば、一年以内にpythonを使って収益化できるようになります。...</span></div></div></a>
<h3>python初心者におすすめのプログラミングスクール</h3>
<p>書籍を読んでもわからない場合には、プログラミングスクールに通うのも一つの方法です</p>
<p>以下はpythonを学ぶことができるプログラミングスクールです</p>
<p>どれも無料体験がありますが、それぞれの特徴は、</p>
<ul>
<li><a href="https://px.a8.net/svt/ejp?a8mat=3N3XRP+DXB0WQ+3XAE+5Z6WY"><strong>WEBCAMP：完全オンラインで即戦力を目指す</strong></a></li>
<li><a href="https://px.a8.net/svt/ejp?a8mat=3N3XRP+DXWGII+4HUE+5YJRM"><strong>アイデミープレミアム：専門職訓練給付金を受けながら格安でpythonを学びたい方向け</strong></a></li>
<li><a href="https://px.a8.net/svt/ejp?a8mat=3HOST7+30CXNE+3GWO+6IWSI"><strong>テックアカデミー：1週間の長期無料体験あり</strong></a></li>
</ul>
<p>詳しい説明は以下の記事でしていますので、ぜひ参考にしてみてください</p>
<a href="https://python-man.club/python_recommendation_school/" class="blog-card"><div class="blog-card-hl-box"><i class="jic jin-ifont-post"></i><span class="blog-card-hl"></span></div><div class="blog-card-box"><div class="blog-card-thumbnail"><img decoding="async" src="https://python-man.club/wp-content/uploads/2022/06/今年のうちに読むべき書籍-6-320x180.jpg" class="blog-card-thumb-image wp-post-image" alt="python プログラミングスクール" width ="162" height ="91" /></div><div class="blog-card-content"><span class="blog-card-title">Pythonや機械学習を学べるプログラミングスクールおすすめ5選</span><span class="blog-card-excerpt">「pythonを学ぶのに、プログラミングスクールに通いたい」「pythonを学べるプログラミングスクールがたくさんあって、よくわからない」「結局、pythonを学ぶのにおすすめのプログラミングスクールってどこなの？」といった疑問をお持ちの方に、pythonを学ぶのにおすすめのプログラミングスクールを紹介していきたいと思います。...</span></div></div></a>
]]></content:encoded>
					
					<wfw:commentRss>https://python-man.club/python_tkinter_menubar/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
