python
  • python-2.7
  • user-interface
  • tkinter
  • 2017-10-11 8 views -3 likes 
    -3

    AND、ORボタンをウィンドウの中央に移動したいのですが、適切な方法はありません。 また、ラベルが中央に表示されません。 私は(パックを使用したくない)グリッドを使ってPythonのボタンを中央に配置する方法は?

    from Tkinter import * 
    
    root = Tk() 
    root.title("BITWISE & and |") 
    Label(root,text='This program will calculate BITWISE AND OR',relief='ridge',font='times 20 bold italic',bg='red',fg='white').grid(row=0,columnspan=5) 
    Label(root, text='Enter 1st Bit ').grid(row=1, column=0) 
    e1 = Entry(root) 
    e1.grid(row=1, column=1) 
    Label(root, text='Enter 2nd Bit').grid(row=2) 
    e2 = Entry(root) 
    e2.grid(row=2, column=1) 
    
    
    def andr(): 
        a = int(e1.get()) 
        b = int(e2.get()) 
        an = a & b 
        Label(root, text='The \'AND\' of the above Bits is = ' + str(an)).grid(row=5) 
    
    
    def ors(): 
        a = int(e1.get()) 
        b = int(e2.get()) 
        o = a | b 
        Label(root, text='The \'OR\' of the above Bits is = ' + str(o)).grid(row=5) 
    
    
    Button(root, text="AND", command=andr).grid(row=3) 
    Button(root, text="OR", command=ors).grid(row=4) 
    
    root.mainloop() 
    

    答えて

    0

    これは、比較的簡単にこの正確なテーマについて、Googleで見つかったチュートリアルや1 ofthemanyのいずれかを使って発見されている可能性があるmanyquestionsを変更でSO。

    Button(root, text="AND", command=andr).grid(row=3, columnspan=5) 
    Button(root, text="OR", command=ors).grid(row=4, columnspan=5) 
    

    columnspanレッツ・オブジェクトは、オブジェクトを中心に説明する。この場合には5に設定する、複数の列にまたがります。

    関連する問題