2017-04-14 1 views
-2

Tkinter를 사용하여 화면에 숫자가 표시되는 곳에서 프로그램을 만들려고합니다. 변수 counter이 하나 아래로 내려 가고 화면의 새 값을 표시하는 창을 아무 곳이나 클릭하면 counter이 하나 더 적습니다.2 Buttons Overlapping Python Tkinter

"upClick"이라는 함수를 호출하는 또 다른 버튼을 추가하는 것이 좋습니다. 함수는 이미 exsists 그리고 번호를 하나씩 올라가서 counter에 1을 추가합니다.

두 번째 단추를 추가하면 전혀 작동하지 않습니다.

나는 많은 것을 시도했으며 여기서 도움을 얻을 수 있거나 누군가가 올바른 방향으로 나를 가리킬 수 있기를 바랍니다. 감사!

코드 :

import tkinter, sys 

root = Tk() 
root.geometry("480x320") #Raspberry Pi touchscreen resolution 
root.title("Counter") 

counter = 30 

def upClick(): 
    counter += 1 
    mButton2.config(text = "", borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100") 

def downClick(): 
    counter -= 1 
    mButton1.config(text = counter, borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100") 

mButton1 = Button(text = counter, command = downClick, height = 4000, width = 320, font = ("Monospace", 200)) 
mButton1.pack() 

mButton2 = Button(text = "", command = downClick, height = 50, width = 50, font = ("Monospace", 10)) 
mButton2.pack() 

root.mainloop() 

감사합니다, 브랜든! (파이썬 3.6.1, 윈도우 10 64 비트)

+0

: 버튼이 중복하려면

, 당신은 놓고 관리자를 사용할 수 있습니다. 대부분의 tkinter 튜토리얼은 당신이 원하는 것을 할 수있는 방법을 다룰 것입니다. –

+0

@ BryanOakley 실제로 시도했지만 버튼 두 개를 한 번에 사용할 수 없습니다. – James

+0

그런 다음 시도한 것을 보여주십시오. –

답변

2

두 버튼을 동시에 작동 시키려면 작은 크기와 글꼴 크기로 시작할 수 있습니다.

버튼이 나타나는 위치에 대해 더 많은 명령을 원할 경우 다른 지오메트리 관리자를 살펴보십시오. 은 본질적으로 다소 제한적이며, 귀하의 경우 충분하지 않은 것으로 보입니다. 당신은 이러한 기본적인 질문을하기 전에 Tkinter의 학습에 약간의 노력을 할 필요가

def upClick(): 
    global counter 
    counter += 1 
    mButton1.config(text = counter, borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100") 


def downClick(): 
    global counter 
    counter -= 1 
    mButton1.config(text = counter, borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100") 

mButton1 = Button(text = counter, command = downClick, height = 4000, width = 320, font = ("Monospace", 200)) 
mButton1.pack() 

mButton2 = Button(text = "", command = upClick, height = 5, width = 5, font = ("Monospace", 10)) 
mButton2.place(anchor="nw") 
+0

예, 두 번째 버튼의'.place (anchor = "nw")'는 작동해야합니다 (그러나 어쨌든 작게 만들어야하는 것처럼 보입니다). – siamezzze

+0

고마워요! upClick에 mButton1.config (text = counter, borderwidth = 0, highlightthickness = 0)를 추가해야했지만 작동했습니다! – James

+0

미래의 독자를 위해 명확하게하기 위해 업데이트되었습니다. 다행 :) – siamezzze