2017-05-22 4 views
1

こんにちは私はpython naughtsを作成し、ゲームをクロスしています。ボードフォーマットを表示する関数を呼び出すと、別のウィンドウでボードフォーマットを開くことができます。だから1つのウィンドウで、どこに行きたいのかを尋ねるプログラムがあり、ボードを別のウィンドウで開きたいと思っているときに表示したいのですが?関数を呼び出す方法は別のウィンドウで開きますか?

def boardf(): 
    os.system("mode con cols=15 lines=7") 
    print (" ") 
    print (" | | ") 
    print (" ---+---+--- ") 
    print (" | | ") 
    print (" ---+---+--- ") 
    print (" | | ") 
+0

あなたはどのようなOSを使用していますか? –

+1

プログラムで開くべき「ウィンドウ」は何ですか?ウィンドウはWindowsコマンドプロンプトシェル( 'cmd.exe')ですか?それともTkinterのようなウィンドウ環境のグラフィカル環境ですか? – davedwards

+0

1)Windows 2)cmd.exe – Atlntic

答えて

0

私はIDLEを使用していますが、これはボールを回転させるのに十分なはずです。 IDLEはPythonをWindowsにダウンロードするときにインストールされるIDEです。 Windowsのキーを押してIDLEを検索することで開くことができます。

コードは初歩的ですが、Tkinterライブラリを使用して新しいウィンドウを作成する方法を知っておくとよいでしょう。私はPython 2.xでTkinterを大文字でインポートする必要があるので、3.xを使用している場合は、インポートを小文字tに変更する必要があります。

import os, Tkinter as tk 

def boardf(): 
    os.system("mode con cols=15 lines=7") 
    print (" ") 
    print (" | | ") 
    print (" ---+---+--- ") 
    print (" | | ") 
    print (" ---+---+--- ") 
    print (" | | ") 

def play_x(): 
    print("implement x logic here") 

def play_y(): 
    print("implement y logic here") 

def create_window(): 
    root_window = tk.Tk() 
    b_x = tk.Button(root_window, text="x", command=play_x) 
    b_y = tk.Button(root_window, text="y", command=play_y) 
    b_x.pack() 
    b_y.pack() 
    root_window.mainloop() 

def main(): 
    boardf() 
    create_window() 

main() 

enter image description here

関連する問題