私はPython2.7でこのコードを使用して、ファイルを開くためのtkinter
を作成しButton
ます。Frame
そのLabel
下にあります。私はそれを作ろうとしているので、ファイルが開かれると、ラベルはパス「file1.name」などをに印刷します。Label
新しいファイルを開くと、それがLabel
再び変更されます。
また、ここで使用している関数よりも関数間でデータを移動する方が良い方法があると思いますがglobal
、今は心配していません。
開いているファイルのデータを関数間で移動して、データを混合して新しいファイルに保存できるようにする必要があります。コードは次のとおりです。
from Tkinter import *
import Tkinter
import tkFileDialog
import tkMessageBox
root = Tkinter.Tk()
global rfile1
global rfile2
rfile1 = ""
rfile2 = ""
class Application(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
self.grid()
self.createWidgets1()
self.createLabels1()
self.createWidgets2()
self.createLabels2()
def createWidgets1(self):
self.oButton = Button(self, text = "open1", command = self.openfile1)
self.oButton.grid()
def createLabels1(self):
self.oLabel = Label(self, text = "whoops")
self.oLabel.grid()
def createWidgets2(self):
self.oButton = Button(self, text = "open2", command= self.openfile2)
self.oButton.grid()
def createLabels2(self):
self.oLabel2 = Label(self, text = "whoops2")
self.oLabel2.grid()
def openfile1(self):
file1 = tkFileDialog.askopenfile(title = "choose a file, *****", parent=root, mode = 'rb')
rfile1 = file1.read()
tkMessageBox.showinfo("oy", rfile1, parent=root)
def openfile2(self):
file2 = tkFileDialog.askopenfile(parent=root, mode='rb')
rfile2 = file2.read()
tkMessageBox.showinfo("hola", rfile2, parent=root)
app = Application()
app.master.title("whiggy whompus")
app.mainloop()