Fonksiyondaki Config neden çalışmıyor?

805079

Centipat
Katılım
2 Temmuz 2024
Mesajlar
74
Çözümler
1
Merhaba. Python'da yazdığım fonksiyondaki confing komutu çalışmıyor. Nasıl düzeltebilirim?

Kod:
def guess():
 a=rd.randint(0,5)
 b=rd.randint(o,5)
 result.config()
 
Kodun tamamını gönderin. Bu şekilde bir şey anlaşılmıyor.
 
Kod:
import tkinter as tk
window=tk.Tk()

window.geometry("800x600+50+100")

import random as rd

window.title('Correct Score')
write=tk.Label(window,text='Welcome',fg='blue',bg='green',font='Times 22 ') .place(x=45, y=10)

write2=tk.Label(window,text='Correct Score Outcome Predictor') .place(x=10, y=50)
  
button2=tk.Button(window,text='click and guess',command=guess) .place(x=360, y=350)

button1=tk.Button(window,text='Close Window',command=window.quit) .place(x=10, y=570)

teamname1=tk.Entry(window) .place(x=230, y=300)

teamname2=tk.Entry(window) .place(x=470, y=300)

def guess():
    a=rd.randint(0,5)
    b=rd.randint(o,5)
    result.config()

result=tk.Label(window, text="",fg='blue',font='Times 22 ') .place(x=245, y=250)

window.mainloop()

correct scoreye aldırış etmeyın😉
 
Python:
import tkinter as tk
import random as rd

def guess():
    a=rd.randint(0,5)
    b=rd.randint(0,5)
    result.config()

window = tk.Tk()
window.geometry("800x600+50+100")
window.title('Correct Score')
write = tk.Label(window,text='Welcome',fg='blue',bg='green',font='Times 22 ') .place(x=45, y=10)
write2 = tk.Label(window,text='Correct Score Outcome Predictor') .place(x=10, y=50)
result=tk.Label(window, text="",fg='blue',font='Times 22 ') .place(x=245, y=250)
button2 = tk.Button(window,text='click and guess',command=guess) .place(x=360, y=350)
button1 = tk.Button(window,text='Close Window',command=window.quit) .place(x=10, y=570)
teamname1 = tk.Entry(window) .place(x=230, y=300)
teamname2 = tk.Entry(window) .place(x=470, y=300)

window.mainloop()

Kodu yazarken bir fonksiyon tanımlamışsınız, içerisinde bir değişken kullanıyor ama bu değişkeni de tanımladığınız fonksiyondan sonra tanımlamışsınız. Kod çalıştırılırken yukarıdan aşağı doğru çalıştırılır. Buna dikkat ederek yazın kodunuzu.

Bende bu hâli çalıştı. Bir deneyin bakalım.
 
result diye bir değişken yok ki def guess() tanımlandığı sırada? a'yı b'yi de hiç bir yere atamıyorsun. b = rd.randint(o, 5) yazmışsın 0 yerine.
Kod:
import tkinter as tk
window=tk.Tk()

window.geometry("800x600+50+100")

import random as rd

window.title('Correct Score')
write=tk.Label(window,text='Welcome',fg='blue',bg='green',font='Times 22 ') .place(x=45, y=10)

write2=tk.Label(window,text='Correct Score Outcome Predictor') .place(x=10, y=50)
  
button2=tk.Button(window,text='click and guess',command=guess) .place(x=360, y=350)

button1=tk.Button(window,text='Close Window',command=window.quit) .place(x=10, y=570)

teamname1=tk.Entry(window) .place(x=230, y=300)

teamname2=tk.Entry(window) .place(x=470, y=300)

result=tk.Label(window, text="",fg='blue',font='Times 22 ') .place(x=245, y=250)

def guess():
    a=rd.randint(0,5)
    b=rd.randint(o,5)
    result.()

window.mainloop()

aa bekleyin deniyorum

Python:
import tkinter as tk
import random as rd

def guess():
    a=rd.randint(0,5)
    b=rd.randint(0,5)
    result.config()

window = tk.Tk()
window.geometry("800x600+50+100")
window.title('Correct Score')
write = tk.Label(window,text='Welcome',fg='blue',bg='green',font='Times 22 ') .place(x=45, y=10)
write2 = tk.Label(window,text='Correct Score Outcome Predictor') .place(x=10, y=50)
result=tk.Label(window, text="",fg='blue',font='Times 22 ') .place(x=245, y=250)
button2 = tk.Button(window,text='click and guess',command=guess) .place(x=360, y=350)
button1 = tk.Button(window,text='Close Window',command=window.quit) .place(x=10, y=570)
teamname1 = tk.Entry(window) .place(x=230, y=300)
teamname2 = tk.Entry(window) .place(x=470, y=300)

window.mainloop()

Kodu yazarken bir fonksiyon tanımlamışsınız, içerisinde bir değişken kullanıyor ama bu değişkeni de tanımladığınız fonksiyondan sonra tanımlamışsınız. Kod çalıştırılırken yukarıdan aşağı doğru çalıştırılır. Buna dikkat ederek yazın kodunuzu.

Bende bu hâli çalıştı. Bir deneyin bakalım.
olmadi hocam
 
Ne yapmaya çalıştığınızı bilmediğim için programın işlevselliğinin çalışıp çalışmadığına bakmadım. Bende en azından uygulama penceresi açılır hâle geldi bu şekilde yapınca.
 
Ne yapmaya çalıştığınızı bilmediğim için programın işlevselliğinin çalışıp çalışmadığına bakmadım. Bende en azından uygulama penceresi açılır hâle geldi bu şekilde yapınca.
Kod:
import tkinter as tk
import random as rd

def guess():
    a=rd.randint(0,5)
    b=rd.randint(0,5)
    result.config(text=a+''+against+''+b)

window = tk.Tk()
window.geometry("800x600+50+100")
window.title('Correct Score')
write = tk.Label(window,text='Welcome',fg='blue',bg='green',font='Times 22 ') .place(x=45, y=10)
write2 = tk.Label(window,text='Correct Score Outcome Predictor') .place(x=10, y=50)
result=tk.Label(window, text="",fg='blue',font='Times 22 ') .place(x=245, y=250)
button2 = tk.Button(window,text='click and guess',command=guess) .place(x=360, y=350)
button1 = tk.Button(window,text='Close Window',command=window.quit) .place(x=10, y=570)
teamname1 = tk.Entry(window) .place(x=230, y=300)
teamname2 = tk.Entry(window) .place(x=470, y=300)

window.mainloop()

Bu kodda pencereyi açtığımız zaman click and guess e basınca butonun biraz ustunde sayilar çıkmalı ama olmuyor

Kaba dilde dersek config isildamiyor hocam komut gibi gorunmuyor
 
Son düzenleme:
Kod:
import tkinter as tk
import random as rd

def guess():
    a=rd.randint(0,5)
    b=rd.randint(0,5)
    result.config(text=a+''+against+''+b)

window = tk.Tk()
window.geometry("800x600+50+100")
window.title('Correct Score')
write = tk.Label(window,text='Welcome',fg='blue',bg='green',font='Times 22 ') .place(x=45, y=10)
write2 = tk.Label(window,text='Correct Score Outcome Predictor') .place(x=10, y=50)
result=tk.Label(window, text="",fg='blue',font='Times 22 ') .place(x=245, y=250)
button2 = tk.Button(window,text='click and guess',command=guess) .place(x=360, y=350)
button1 = tk.Button(window,text='Close Window',command=window.quit) .place(x=10, y=570)
teamname1 = tk.Entry(window) .place(x=230, y=300)
teamname2 = tk.Entry(window) .place(x=470, y=300)

window.mainloop()

Bu kodda pencereyi açtığımız zaman click and guess e basınca butonun biraz ustunde sayilar çıkmalı ama olmuyor

Kaba dilde dersek config isildamiyor hocam komut gibi gorunmuyor
Python:
import tkinter as tkimport random as rd

def guess():
a = rd.randint(0, 5)
b = rd.randint(0, 5)
result.config(text=str(a) + ' ' + 'against' + ' ' + str(b))

window = tk.Tk()
window.geometry("800x600+50+100")
window.title('Correct Score')
write = tk.Label(window, text='Welcome', fg='blue', bg='green', font='Times 22 ').place(x=45, y=10)
write2 = tk.Label(window, text='Correct Score Outcome Predictor').place(x=10, y=50)
result = tk.Label(window, text="", fg='blue', font='Times 22 ')
result.place(x=245, y=250)
button2 = tk.Button(window, text='click and guess', command=guess).place(x=360, y=350)
button1 = tk.Button(window, text='Close Window', command=window.quit).place(x=10, y=570)
teamname1 = tk.Entry(window).place(x=230, y=300)
teamname2 = tk.Entry(window).place(x=470, y=300)

window.mainloop()
şuan çalışıyor.
 

Technopat Haberler

Geri
Yukarı