因此,在我在Tkinter GUI上进行了一些网络研讨会和一些谷歌搜索后,我得到了一个小型宾果应用程序(Windows btw)的作业。
我已经成功制作了一些正常运行的小应用程序,但这次我尝试用我认为的知识来制作它。
无论如何,在那个Bingo应用程序中,我想要50个代表宾果卡50个数字的标签,5个10个数字的行。 我知道如何对齐它们,但它们需要首先出现。
你能查看我的代码并评估我的错误吗?
忽略许多荷兰语评论:)
'''
iWMMMM0.
XM#o:..iIMM.
MM. :XC17, YM8
M@ v@9. .W# ,M,
#M 7@i ,0$: M0 MM
.M. @7 M@t, ME MQ
MM iM. #$Ci$Q ;M#CCY:.
CM ,M, b#$; v;7IEW@MMM@1
MQ WQ .tE0Q2nCCYc;i,:7#MMi
:M @b . .. .:YCb0U: YMM.
WM E@i .... ,i: ,b#; bMQ,SbW06i
oM MC ... MME9#$Y . .#b SM@b2tob@MM1
Mi @7 ... @M .v iMt ... @X :CoUzt: :MM, nWM@Bc :nQ#$Ui
M: @Y .. M9 MM@ b# ... Zb1#Zi. .;Z#Y SMi MM#t;vCMM,CMM0C77bMM8
M, @7 .. @6 Y7 ;Mn ... #QB. ,#b ZM MM .n9U; bMM. ;z2U7 MM
M: @Y ., @9.;tQQv ... ;MQ, :@; Mv MM X$: M; , ;$2. 7@i M8
M: @7 .. #BW1i ..,:Y$Mt$ MX MMtiEM: E@: ZME,.W$c ; c@ .M
M: @Y ., ME .. .ZMM8o89 QM. i;U@@ .Zb7: ,BBYzQ bM@ Mi M
Mi @X .. M, iMM@WS :bWQb, ,#M1;IoIX 1@c bMMX iM I@E$CM M, M
.MM @7 ., Mn EM8AEE#: . v$AWQ#$Q#MMIWz, ;$Z$ MMzW2 M@ $ZY$C bM CM
MZ ib@i .. @@. ;t $z@. ., CWUWnE$b7: :Y #$c MEYY .MM8 :; vM. M1
iM iMi .., #bWI,..M@i#C .., Mv i#E. UMM2 @BC oC;tMMCES .@M MM
MY E0 ... S@i:Z$MZ .Mv ... M8 7WEz MnZo @obUA: ic.7bEW$#M@C iMM
CMi I@; .. b#; $$ ... ,MQ 7$Zz @zbz @IXW#E69z. 80 ::iAMM;
iM$ .$Qi . :Z$Q0Q#6. ... MQ0 C$b1 MtQ7 YZWW,.c$@@ MC MMM@b.
MM7 iBWv. .., .M#7$ v$8; vQ0:iCAM: :#bM0 nMU BM
:MM1 .6$Q7: ;MMS:Q7 @#i12EMzEESB# .7:,,2M@ MM
,MM#: ,1E$BQbZ6EBMM@; iQQ@@B$72n7i.,vo tQQIZQ$WC .#MQ
6MM@o;,,:ivY;i,,iEMM...,,:iC2Q#MMMQ$M$..,i::,;9MMZ
YIEbEAU269086, ;Bb08bAz;:. 7QbEZb8boi
'''
##Basale geimporteerde functies
from tkinter import*
#self=()
#Importeert de randomfucntie
#import random
#Importeert de Python Debugger
#Runnen met pdb.run
#import pdb
#Importeert de PIL Python Image Library
#from PIL import Image, ImageTK
#image = image.open("bestandsnaam.jpg")
#photo ImageTK.PhotoImage(image)
#Een afbeelding op een label
#label = Label(image=photo(als photo de naam van de variable is))
#label.image = photo (bewaren als referentie?<- geen idee nog)
'''
#=# Start van metainfo class/klasse
class MetaBingPy():
def __init__(self):
super(MetaBingPy, self).__init__()
self.parent = parent
self.pack()
MetaBingPy.BingoPyC(self)
##Functie voor random number generator
def BingoPyC:
self.root = Tk()
self.root.title("Python Bingo")
#=#Einde metainfo class
'''
###def random.randint(1,50)
#####of# randrange(1,50)
##GUI voor BingPy, moet root heten. Geen eigen naam, zoals:
##BingPyGUI wat ik had.
root = Tk()
root.wm_title("Bingo Python")
root.wm_maxsize("800","600")
root.wm_minsize("800","600")
#root.wm_grid(baseWidth="800", baseHeight="800")
#root.grid("800x800")
#_tkinter.TclError: wrong # args: should be "wm grid window ?baseWidth baseHeight
#widthInc heightInc?"
##self.title="Bingo Python"
###GUI voor BingPy code, altijd afsluiten met:
###bovenaan
root.mainloop()
'''
#Algemene Python Bingo klasse
class BingoPy
def
'''
#Labels voor alle nummers (50)
label1 = Label(root, text="1jghjgjkhjhg")
label1.grid()
label1.pack()
label2 = Label(root, text="2")
label2.grid()
label2.pack()
label3 = Label(root, text="3")
label3.grid()
label3.pack()
label4 = Label(root, text="4")
label4.grid()
label4.pack()
label5 = Label(root, text="5")
label5.grid()
label5.pack()
label6 = Label(root, text="6")
label6.grid()
label6.pack()
label7 = Label(root, text="7")
label7.grid()
label7.pack()
label8 = Label(root, text="8")
label8.grid()
label8.pack()
label9 = Label(root, text="9")
label9.grid()
label9.pack()
label10 = Label(root, text="10")
label10.grid()
label10.pack()
label11 = Label(root, text="11")
label11.grid()
label11.pack()
label12 = Label(root, text="12")
label12.grid()
label12.pack()
Label13 = Label(root, text="13")
Label13.grid()
Label13.pack()
label14 = Label(root, text="14")
label14.grid()
label14.pack()
label15 = Label(root, text="15")
label15.grid()
label15.pack()
label16 = Label(root, text="16")
label16.grid()
label16.pack()
label7 = Label(root, text="17")
label17.grid()
label17.pack()
label18 = Label(root, text="18")
label18.grid()
label18.pack()
label19 = Label(root, text="19")
label19.grid()
label19.pack()
label20 = Label(root, text="20")
label20.grid()
label20.pack()
label21 = Label(root, text="21")
label21.grid()
label21.pack()
label22 = Label(root, text='22')
label22.grid()
label22.pack()
label23 = Label(root, text="23")
label23.grid()
label23.pack()
label24 = Label(root, text="24")
label24.grid()
label24.pack()
label25 = Label(root, text="25")
label25.grid()
label25.pack()
label26 = Label(root, text="26")
label26.grid()
label26.pack()
label27 = Label(root, text="27")
label27.grid()
label27.pack()
label28.Label(root, text="28")
label28.grid()
label28.pack()
label29 = Label(root, text="29")
label29.grid()
label29.pack()
label30 = Label(root, text="30")
label30.grid()
label30.pack()
label31 = Label(root, text="31")
label31.grid()
label31.pack()
label32 = Label(root, text="32")
label32.grid()
label32.pack()
label33 = Label(root, text="33")
label33.grid()
label33.pack()
label34 = Label(root, text="34")
label34.grid()
label34.pack()
label35 = Label(root, text="35")
label35.grid()
label35.pack()
label36 = Label(root, text="36")
label36.grid()
label36.pack()
label37 = Label(root, text="37")
label37.grid()
label37.pack()
label38 = Label(root, text="38")
label38.grid()
label38.pack()
label39 = Label(root, text="39")
label39.grid()
label39.pack()
label40 = Label(root, text="40")
label40.grid()
label40.pack()
label41 = Label(root, text="41")
label41.grid()
label41.pack()
label42 = Label(root, text="42")
label42.grid()
label42.pack()
label43 = Label(root, text="43")
label43.grid()
label43.pack()
label44 = Label(root, text="44")
label44.grid()
label44.pack()
label45 = Label(root, text="45")
label45.grid()
label45.pack()
label46 = Label(root, text="46")
label46.grid()
label46.pack()
label47 = Label(root, text="47")
label47.grid()
label47.pack()
label48 = Label(root, text="48")
label48.grid()
label48.pack()
label49 = Label(root, text="49")
label49.grid()
label49.pack()
label50 = Label(root, text="50")
label50.grid()
label50.pack()
#Maakt het rood (en als het mogelijk is: doorstrepen) als het getrokken is
#Waarde-return in veld + niet meer zelfde nummer kunnen kiezen
#--------------------------------------------------------------------------
#Knoppen voor afsluiten en nieuw getal
##Afsluiten
#def bingoclose():
# print("Bingo Afsluiten")
'''
bAfsluiten = Button(root,text"Sluit Bingo Af")
bAfsluiten.pack()
'''
'''
{
'title' : ['BingPy'],
'summary' : ['Simple Bingo Python Application with rand.num generator'],
'authors' : ['Thomas']
#'date' : ['2015']
'base_url' : ['http://www.rainydays.eu']
}
'''
'''
Info en weblinks:
https://docs.python.org/3/library/random.html?highlight=random#module-random
http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf (Python 2.7!)
https://wiki.scinet.utoronto.ca/wiki/images/4/41/Pwcgui.pdf
http://stackoverflow.com/questions/3643235/how-to-add-a-margin-to-a-tkinter
-window Margins in Python (padx, pady)
'''
答案 0 :(得分:0)
list
。root.mainloop()
。这开始了一个循环。在窗口关闭之前没有执行任何操作,这意味着它必须在最后。grid()
和pack()
,更不用说同一个子窗口小部件。label7 =
而非label17 =
,以及label28.Label
而不是label28 = Label
。如果你使用了list
,那么大多数都不会发生。考虑到所有这些要点(最后一个除外)的结果代码如下所示。
from tkinter import *
root = Tk()
root.wm_title("Bingo Python")
root.wm_maxsize("800","600")
root.wm_minsize("800","600")
labels = [Label(root, text=i) for i in range(1, 51)]
for label in labels:
label.pack()
root.mainloop()