2017-03-29 14 views
-1

すべてのテキストを1行に整列させるのにアンカー= Wを使用していますが、できません。私は例のように、番号を持つ単一の行のすべてを表示するPython tkinterアンカーを使用したテキスト表示GUI = W

GUIスクリプト

:私も先頭で列挙を表示したい は、そのが動作していない試みました。

1.U1a1400  3C  CAN Initialisation is Failure - no sub type information 
2.U000188  3C  High Speed CAN Communication Bus - bus off 

コードは以下の通りです:

のMS Accessに接続する
import pypyodbc 
from Tkinter import * 
from DataStructure import * 
row = '' 
dtc_code = '' 

def UserInput(): 
global UI_MainForm 
global row 
global dtc_code 
UI_MainForm = Tk() 

#Initialization of Main Window 


UI_MainForm.geometry("1000x575+500+50") 
UI_MainForm.title("Script") 

# labelframe = LabelFrame(UI_MainForm,text="Please select :",width=400, height=800,bd = 2) 
# labelframe.pack(fill="both") 
# labelframe.config(relief=RIDGE) 
# for xx,yy in zip(DTC_CODE,FAULT_TYPES): 
    # temp_text1 = '{0} - {1}'.format(xx,yy) 

    for dtccodes,faulttypes in zip(DTC_CODE,FAULT_TYPES): 
      temp_text = '{0}  {1}'.format(dtccodes,faulttypes) 

     Label(UI_MainForm, text= temp_text).pack(anchor = W) 


    for menu1,menu2 in zip(DTC_Description,DTC_Description1): 
      temp_text = '{0} - {1}'.format(menu1,menu2) 
     Label(UI_MainForm, text= temp_text).pack(anchor = W) 

    # for menu2 in DTC_Description1: 
     # Label(labelframe, text= menu2).pack(anchor = W,pady = 2) 





# Label(labelframe, text=array2).pack(anchor = E,pady = 2) 

UI_MainForm.mainloop() 
return; 


response = '59 02 FF DA 14 00 3C C0 01 88 3C 5B 18 2F 3C C3 00 00 3C E1 00 00 3C E1 01 00 3C C3 00 57 3C E0 1A 54 3C 50 24 00 3C' 

DTCLogged = response.split(' ') 

DTCLogged = DTCLogged[3:] 
print DTCLogged 
DTCLoggedLen = len(DTCLogged) 
print DTCLoggedLen 
NumberOfDTC = DTCLoggedLen/4 
print NumberOfDTC 
loopindex = 0 
DTCRecord =[] 
DTC_CODE = [] 
FAULT_TYPES = [] 
DTC_Description = [] 
DTC_Description1 = [] 
while (loopindex+4) <= DTCLoggedLen: 


Record = DTCLogged[loopindex]+' '+DTCLogged[loopindex+1]+' '+DTCLogged[loopindex+2] 
# print Record 
#print DTCLogged[loopindex] 
DTCRecord.append(Record) 




if((int(DTCLogged[loopindex], 16) & 0xC0) == 0): 
    dtc_designator = 'P' 
    #print dtc_designator 
elif((int(DTCLogged[loopindex], 16) & 0xC0) == 64): 
    dtc_designator = 'C' 
    #print dtc_designator 
elif((int(DTCLogged[loopindex], 16) & 0xC0) == 128): 
    dtc_designator = 'B' 
    #print dtc_designator 
else: 
    dtc_designator = 'U'; 
    #print dtc_designator 

#y = int(DTCLogged[loopindex], 16) & 0x30 
global dtc_designator1 
if((int(DTCLogged[loopindex], 16) & 0x30) == 0): 
    dtc_designator1 = '0' 
    #print dtc_designator1 
elif((int(DTCLogged[loopindex], 16) & 0x30) == 16): 
    dtc_designator1 = '1' 
    #print dtc_designator1 
elif((int(DTCLogged[loopindex], 16) & 0x30) == 32): 
    dtc_designator1 = '2' 
    #print dtc_designator1 
else: 
    dtc_designator = '3'; 
    #print dtc_designator1 

z = int(DTCLogged[loopindex], 16) & 0x0F 
global dtc_designator2 
dtc_designator2 = hex(z)[2:] 
#print dtc_designator2 

dtc_code = dtc_designator + dtc_designator1 + dtc_designator2 + DTCLogged[loopindex+1] 
# print dtc_code 

dtc_code1 = dtc_code + DTCLogged[loopindex+2] 
# Value = [] 
DTC_CODE.append(dtc_code1) 
# return Value 

fault_type = DTCLogged[loopindex+3] 
FAULT_TYPES.append(fault_type) 

:側のテキストラベルが表示されます内部

cursor1.execute("SELECT Field2 FROM DTC_CODES Where Field1 = '{}'".format(dtc_code)) 

for row in cursor1.fetchone(): 
    print row 
DTC_Description.append(row) 

cursor2 = connection.cursor() 
cursor2.execute("SELECT Field2 FROM FAULT_TYPES Where Field1 = '{}'".format(DTCLogged[loopindex+2])) 
for row1 in cursor2.fetchone(): 
    DTC_Description1.append(row1) 

loopindex = loopindex+4 


UserInput() 
+0

も、あなたはTkのにテキストを配置する部分ではどこ?あなたの質問に関連するコードだけを残してください。 – abccd

+0

UI_MainForm.mainloop()の後のすべてを削除するという意味です。 – abccd

+0

いいえ、削除しません。上記のように1行で印刷したいだけです。イメージワットで私は今結果を得る –

答えて

1

anchor=W指定します。他のラベルとの関連でラベルが表示される場所には影響しません。

特に指定しない限り、packは、オプションside='top'を使用します。したがって、Label(UI_MainForm, text= temp_text).pack(anchor = W)はこのラベルをウィンドウ内の他のものの下に置きます。

あなたが水平線のすべてをしたい場合は、side='left'を使用します。

Label(UI_MainForm, text= temp_text).pack(side='left', anchor = W) 
関連する問題