2017-07-26 11 views
-1

私は、Java、C++、C#などの言語とTkinterライブラリのような非常に異なるクラスのコンセプトを使って、Pythonプログラミングにかなり新しいです。私は何か基本的なことをしようとしています。最初に、ユーザーが文字列値を入力できるようにするフレームを作成します。その文字列値をメモリに格納し、そのフレームを終了します。特定のファイルを選択できるようにする新しいファイルブラウザを作成し、選択したファイルの名前を、先にメモリに格納されている文字列に変更します。私はそれを行うための具体的なスニペットを持っていませんが、私は私が望む結果を与えるために組み合わせることができる2つのコードを持っています。どのように2つのtkinterウィンドウを順に開きますか?

あなたがエントリーしてFILE_PATH = askopenfilenameを使用したい場合は、関数os.renameで、OSのライブラリを使用する必要がありますよりも、あなたは、このexample.Butのようasksaveasfilenameにしようとしないのはなぜ
enter code here 
# This is the snippet for the input user 
def printtext(): 
    global e 
    string = e.get() 
    return string 

from Tkinter import * 
root = Tk() 

root.title('Name') 

e = Entry(root) 
e.pack() 
e.focus_set() 

b = Button(root,text='okay',command=printtext) 

b.pack(side='bottom') 

root.mainloop() 

# This is for the file browser 

import Tkinter,tkFileDialog 

root = Tkinter.Tk() 
file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file') 

答えて

0

(と思います) 。このコードはPython 3で書かれています。もしあなたが単にライブラリの名前を変更するよりもpython2を使っているならば。

from tkinter import * 
import tkinter.filedialog as fd 

def main(): 

    root = Tk() 
    root.title('Name') 
    #e = Entry(root) 
    #e.pack() 

    #e.focus_set() 
    b = Button(root,text='okay',command= lambda:printtext(e))  
    b.pack(side='bottom') 

    root.mainloop() 

def printtext(e): 
    #string = e.get() 
    #print(string) 
    file = fd.asksaveasfile(title='Choose a file') 
    #print(file) 

main() 
関連する問題