私はPythonプログラミングに新しく、自分自身を解決できないような基本的な質問があります。誰かがこの問題を解明できることを願っています!Python Tk()Buttonコマンドが完全に機能していない
ユーザーと(ランダム)コンピューターの間で基本的なロック、ペーパー、はさみゲームを実行する.py
ファイルを作成しました。これはtk()
経由のGUIを使用しています。
次に、別の.py
ファイルを作成しました。今回は、全体のメニューGUIを作成しました。そこからRock、Paper、Scissorsのゲームを実行することができます。私はこれを作成することができますtk()
罰金、RPSゲームを選択するボタンは、ゲームがロードされますが、今回は全く動作しません!私はボタンを押すことができますが、ゲームを進めません。
ここgame.py
のための私のコードは次のとおりです。
from tkinter import *
from tkinter.ttk import *
import random
def gui():
<game code goes in here, including other functions>
root=Tk()
root.title("Rock, Paper, Scissors")
# more code to define what this looks like
# including a Frame, buttons, labels, etc>
if __name__=='__main__':
gui()
そして私は、全体的なゲームメニュー、menu.py作成:誰もが何かを明らかに見ることができる場合、私に知らせてください
from tkinter import *
from tkinter.ttk import *
import random
import game
main=Tk()
main.title("J's games")
mainframe=Frame(main,height=200,width=500)
mainframe.pack_propagate(0)
mainframe.pack(padx=5,pady=5)
intro=Label(mainframe,
text="""Welcome to J's Games. Please make your (RPS) choice.""")
intro.pack(side=TOP)
rps_button=Button(mainframe, text="Rock,Paper,Scissors", command=game.gui)
rps_button.pack()
test_button=Button(mainframe,text="Test Button")
test_button.pack()
exit_button=Button(mainframe,text="Quit", command=main.destroy)
exit_button.pack(side=BOTTOM)
main.mainloop()
を。なぜ私はそれが別の機能(ボタンコマンド)に組み込まれているのか分かりません。私はIDLEのデバッグを試みましたが、それは私の上でフリーズしているようです!
1つの問題は、2つのルートウィンドウ(つまり、 'Tk()'を2回呼び出すことです)。 tkinterプログラムはちょうど1つのルートウィンドウを持つべきです。 –
書込みボックスにコードを1度だけインデントしてください。書式設定の後に一杯になるので、切り取りと貼り付けができます。 –