私はTkinterを使用してPythonでグラフ電卓を作成しています。私の目的は、電卓を次のように見せることです-http://prntscr.com/k6exeu
私は現在も電卓を作っているので、足りないものがたくさんありますが、最初に設計を行うことにしました。コードを実行すると、次のようになります-http://prntscr.com/k6eyhm
これを修正するのに助けが必要です。エラーを見つけることができるように、ここまでコードを貼り付けます。
import sys
try:
from Tkinter import *
import tkMessageBox
except ImportError:
from tkinter import *
from tkinter import messagebox
window = Tk()
window.title("PyCalc")
window.geometry("500x500")
user_output = Entry(width=50, state='readonly', justify=CENTER)
zero = Button(text="0", height=3, width=3, justify=LEFT)
one = Button(text="1", height=3, width=3, justify=LEFT)
two = Button(text="2", height=3, width=3, justify=LEFT)
three = Button(text="3", height=3, width=3, justify=LEFT)
four = Button(text="4", height=3, width=3, justify=LEFT)
five = Button(text="5", height=3, width=3, justify=LEFT)
six = Button(text="6", height=3, width=3, justify=LEFT)
seven = Button(text="7", height=3, width=3, justify=LEFT)
eight = Button(text="8", height=3, width=3, justify=LEFT)
nine = Button(text="9", height=3, width=3, justify=LEFT)
user_output.grid(row=0)
zero.grid(row=4, column=3, sticky=N+S+E+W)
one.grid(row=1, column=1, sticky=N+S+E+W)
two.grid(row=1, column=2, sticky=N+S+E+W)
three.grid(row=1, column=3, sticky=N+S+E+W)
four.grid(row=2, column=1, sticky=N+S+E+W)
five.grid(row=2, column=2, sticky=N+S+E+W)
six.grid(row=2, column=3, sticky=N+S+E+W)
seven.grid(row=3, column=1, sticky=N+S+E+W)
eight.grid(row=3, column=2, sticky=N+S+E+W)
nine.grid(row=3, column=3, sticky=N+S+E+W)
window.mainloop()
誰かが私を助けてくれるなら、私はとても幸せです:)
-CodeExecution
必要なレイアウトを取得するには、エントリuser_output
がすべてのボタン列にまたがる必要があります。これは、columnspan
グリッドオプションを使用して実現できます。
user_output.grid(row=0, columnspan=3)
さらに、列を指定しなかったuser_output.grid
ため、デフォルトでは列0に配置され、左端のボタンは列1に配置されます。
user_output.grid(row=0, columnspan=3)
zero.grid(row=4, column=2, sticky=N+S+E+W)
one.grid(row=1, column=0, sticky=N+S+E+W)
two.grid(row=1, column=1, sticky=N+S+E+W)
three.grid(row=1, column=2, sticky=N+S+E+W)
four.grid(row=2, column=0, sticky=N+S+E+W)
five.grid(row=2, column=1, sticky=N+S+E+W)
six.grid(row=2, column=2, sticky=N+S+E+W)
seven.grid(row=3, column=0, sticky=N+S+E+W)
eight.grid(row=3, column=1, sticky=N+S+E+W)
nine.grid(row=3, column=2, sticky=N+S+E+W)
与える
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加