我試圖做一個程序中的按鈕的選擇, 進行到下一個程序,使用Tkinter(窗口中的python 2.7)。 我一直在谷歌運氣沒有運氣。我可能是 缺乏正確的術語和流行語。無論如何,我希望問題是清楚的。謝謝。從一個文件攜帶選擇到下一個
讓我試試並演示如下: ...所以我們有兩個文件:PROGRAM_1.py和PROGRAM_2.py他們將在單獨的文件。
PROGRAM_1.py
from Tkinter import *
import os
import Tkinter as tk
start_color = ["blue", "red"]
root = Tk()
root.title("please choose a starting color")
# Set background #
root.configure(background="green")
root.geometry("600x150")
# Buttons #
topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=LEFT)
start_color[0] = Button(topFrame, text="Choose Blue", fg="black", bg="white", font='bold')
start_color[1] = Button(topFrame, text="Choose Red", fg="black", bg="white", font='bold')
start_color[0].pack(side=LEFT)
start_color[1].pack(side=LEFT)
def blue(event):
print "u chose the blue"
os.system("PROGRAM_2.py")
# then exit and startup PROGRAM_2".py
start_color[0].bind("<Button-1>", blue)
def red(event):
print "u chose the red"
os.system("PROGRAM_2.py")
# then exit and startup PROGRAM_2".py
start_color[1].bind("<Button-1>", red)
root.mainloop()
PROGRAM_2.py
from Tkinter import *
import os
import Tkinter as tk
start_color = ["blue", "red"]
root = Tk()
print "your color is"
print start_color["......."] # <--- And then the choice from PROGRAM_1.py
root.mainloop()
謝謝。我會放棄它。 – ToFo 2015-03-03 13:01:44
我無法完成這項工作。讓我告訴你我做了什麼。首先,您要刪除PROGRAM_1.py中的按鈕 - 所以我再次添加它們 – ToFo 2015-03-03 13:32:35
不,我沒有刪除按鈕 - 只是將調用替換爲'os.system()'來傳遞命令行參數。 – mhawke 2015-03-03 13:35:31